Monday, November 05, 2007

Emacs goto-column function

Found this at http://www.icce.rug.nl/edu/1/cygwin/extra/dot.emacs.


Put it in your .emacs file.


(defun goto-column-number (number)
"Untabify, and go to a column number within the current line (1 is beginning
of the line)."
(interactive "nColumn number ( - 1 == C) ? ")
(beginning-of-line)
(untabify (point-min) (point-max))
(while (> number 1)
(if (eolp)
(insert ? )
(forward-char))
(setq number (1- number))))


To use it in emacs, use "Esc-X goto-column-number", enter, and type column number of the current line.

3 comments:

Marcelle said...

Nice thing. Tnx. :)

Mas said...

Thanks! It's so useful!

OtherMichael said...

You can also add a wrapper to the move-to-column function:

;; move to column in current line
(defun repos (position)
(interactive "nPosition: ")
(move-to-column position)
)