Add two new functions to move to beginning/end of a line

They consider visual lines and indentation.  However, they don’t work in
Org-mode yet.

Inspired by @bbatsov:
http://emacsredux.com/blog/2013/05/22/smarter-navigation-to-the-beginning-of-a-line/
This commit is contained in:
Gergely Polonkai 2016-11-15 08:58:45 +01:00
parent 33e05c054a
commit ab56d6f449
2 changed files with 33 additions and 0 deletions

View File

@ -945,6 +945,8 @@
("M-t s" . transpose-sentences)
("M-t p" . transpose-paragraphs)
("M-t W" . transpose-windows)
("C-a" . gpolonkai/move-to-beginning-of-line)
("C-e" . gpolonkai/move-to-end-of-line)
:map ctl-x-map
("C-y" . duplicate-line)
("_" . maximize-window)

View File

@ -127,3 +127,34 @@ copied to the kill-ring."
(let ((beginning (progn (beginning-of-line) (point)))
(end (progn (end-of-line) (point))))
(copy-region-as-kill beginning end))))
(defun gpolonkai/move-to-beginning-of-line ()
"Move to different beginnings of the line; in order: beginning
of the visual line if `visual-line-mode' is active, the first
non-whitespace (indentation), the actual beginning of the line.
This function will jump between the first character and the
indentation if used multiple times.
Inspired by Bozhidar Batsov's solution:
http://emacsredux.com/blog/2013/05/22/smarter-navigation-to-the-beginning-of-a-line/"
(interactive)
(let ((last-pos (point)))
(when visual-line-mode
(beginning-of-visual-line))
(when (= (point) last-pos)
(back-to-indentation))
(when (= (point) last-pos)
(beginning-of-line))
(when (= (point) last-pos)
(back-to-indentation))))
(defun gpolonkai/move-to-end-of-line ()
"Move to the end of the line. If `visual-line-mode' is active,
jump to the end of the visual line first. The jump to the
actual end of the line."
(interactive)
(let ((last-pos (point)))
(when visual-line-mode
(end-of-visual-line))
(when (= (point) last-pos)
(end-of-line))))