Moving to the start of a code line: Emacs

后端 未结 5 1853
自闭症患者
自闭症患者 2021-01-31 15:18

I use emacs for development and very often need to move to the start of a line (C-a). However if the line is indented, I\'d like to move to the point at which code st

5条回答
  •  不思量自难忘°
    2021-01-31 15:41

    I do the same toggling trick as Trey, but defaulting to indentation instead of to beginning of line. It takes slightly more code because there's no "at-beginning-of-indentation" function that I know of.

    (defun smart-line-beginning ()
      "Move point to the beginning of text on the current line; if that is already
    the current position of point, then move it to the beginning of the line."
      (interactive)
      (let ((pt (point)))
        (beginning-of-line-text)
        (when (eq pt (point))
          (beginning-of-line))))
    

    This will probably let you continue to use Ctrl-a and have it do what you want most often, while still being able to get the built-in behavior easily.

提交回复
热议问题