Xref: utzoo comp.emacs:7866 gnu.emacs:2390 Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!usc!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!caesar.cs.montana.edu!cambridge.apple.com!bloom-beacon!bloom-beacon!athena.mit.edu!daloera From: daloera@athena.mit.edu (Daniel A. Loera) Newsgroups: comp.emacs,gnu.emacs Subject: Line and Column numbers Message-ID: <1990Feb28.123000.15869@athena.mit.edu> Date: 28 Feb 90 12:30:00 GMT Sender: news@athena.mit.edu (News system) Reply-To: daloera@athena.mit.edu (Daniel A. Loera) Distribution: usa Organization: Massachusetts Institute of Technology Lines: 92 I have received the following code from tac@CS.BROWN.EDU. It is supposed to put the col and row numbers on the mode line. What follows is exactly what I received from him. You may have to hack around with the code to get it to work for you. -> Start of tac@CS.BROWN.EDU's e-mail: these will do it, but will only be correct for arrow keys, not for forward-sexp for ex. (defun teds-forward-char (&rest dummy) (interactive) (forward-char 1) (update-modeline)) (defun teds-backward-char (&rest dummy) (interactive) (backward-char 1) (update-modeline)) (defun teds-previous-line (&rest dummy) "Previous-line, maintains column, updates cursor pos" (interactive) (let ((old-row 0)) (if (not (or (eq last-command 'teds-previous-line) (eq last-command 'teds-next-line))) (setq *column* (current-column))) (setq old-row (current-row)) (previous-line 1) (move-to-column *column*) (if (and (/= old-row 0) (not (eql (current-window) *keypad-window*))) (update-modeline)))) (defun teds-next-line (&rest dummy) "Next-line, maintains column, updates cursor pos" (interactive) (let ((old-row 0)) (if (not (or (eq last-command 'teds-previous-line) (eq last-command 'teds-next-line))) (setq *column* (current-column))) (setq old-row (current-row)) (next-line 1) (move-to-column *column*) (if (/= old-row (- (window-height) 2)) (update-modeline)))) (defun current-column () "Returns current column #, from 0." (let ((pos (dot))) (beginning-of-line) (prog1 (- pos (dot)) (goto-char pos)))) (defun current-row () "Returns current row #, from screen top, from 0." (let* ((pos (point)) (top (window-start)) (count 0)) (beginning-of-line) (while (/= (point) top) (forward-line -1) (setq count (1+ count))) (goto-char pos) count)) (defun update-modeline () "Update modeline, including cursor position." (if (not (eql (current-window) *keypad-window*)) (setq mode-line-format (cons (concat (format "row %2s " (current-row)) (format "col %2s " (current-column))) (cdr mode-line-format))))) ;; (global-unset-key "\M-[") ;; (global-set-key "\M-[A" 'previous-line) ; r8 ;; (global-set-key "\M-[B" 'next-line) ; r14 ;; (global-set-key "\M-[C" 'forward-char) ; r12 ;; (global-set-key "\M-[D" 'backward-char) ; r10 - Ted p.s. anything undefined is probably my own hacks and can be ignored.