help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Going to line n, column m


From: Pascal J. Bourguignon
Subject: Re: Going to line n, column m
Date: Tue, 07 Oct 2008 19:23:16 +0200
User-agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/22.2 (gnu/linux)

Mauricio <briqueabraque@yahoo.com> writes:
> I think this is simple, but I wasn't able
> to find it anywhere: how can I tell emacs
> I want to go to line x, column y?

Usually, x is the column, and y is the line.

(defun goto-xy (column line)
  (interactive "nColumn: 
nLine: ")
  (let ((lines (count-lines (point-min) (point-max))))
    (cond
      ((< line 0)     (error "Cannot go before the beginning of buffer."))
      ((< line lines) (beginning-of-buffer) (forward-line line))
      (t (end-of-buffer) (insert (make-string (- line lines) 10))))
    (let ((columns (- (progn (end-of-line)       (point))
                      (progn (beginning-of-line) (point)))))
      (cond ((< column 0) (error "Cannot go before the beginning of line"))
            ((< column columns) (forward-char column))
            (t (end-of-line) (insert (make-string (- column columns) 32)))))))


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

"Our users will know fear and cower before our software! Ship it!
Ship it and let them flee like the dogs they are!"


reply via email to

[Prev in Thread] Current Thread [Next in Thread]