diff --git a/README.md b/README.md index 5b6df2f..3cc5855 100644 --- a/README.md +++ b/README.md @@ -208,6 +208,7 @@ Keybinding | Description F12 | Toggle the Emacs menu bar. C-x g | Open Magit's status buffer. C-= | Run `expand-region` (incremental text selection). +C-a | Run `prelude-move-beginning-of-line`. Read [this](http://emacsredux.com/blog/2013/05/22/smarter-navigation-to-the-beginning-of-a-line/) for details. #### Prelude Mode @@ -417,6 +418,17 @@ personal Emacs customization to enable them permanently: (setq prelude-guru nil) ``` +### Customized C-a behavior + +Prelude overrides `C-a` to behave as described +[here](http://emacsredux.com/blog/2013/05/22/smarter-navigation-to-the-beginning-of-a-line/). If +you don't like that simply add this to your personal config: + +```lisp +(global-set-key [remap move-beginning-of-line] + 'move-beginning-of-line) +``` + ### Windows compatibility While everything in Prelude should work fine in Windows, I test it only diff --git a/core/prelude-core.el b/core/prelude-core.el index 87d5721..3a3d16a 100644 --- a/core/prelude-core.el +++ b/core/prelude-core.el @@ -117,6 +117,32 @@ Passes ARG to command `kill-whole-line' when provided." (kill-whole-line arg) (back-to-indentation)) +(defun prelude-move-beginning-of-line (arg) + "Move point back to indentation of beginning of line. + +Move point to the first non-whitespace character on this line. +If point is already there, move to the beginning of the line. +Effectively toggle between the first non-whitespace character and +the beginning of the line. + +If ARG is not nil or 1, move forward ARG - 1 lines first. If +point reaches the beginning or end of the buffer, stop there." + (interactive "^p") + (setq arg (or arg 1)) + + ;; Move lines first + (when (/= arg 1) + (let ((line-move-visual nil)) + (forward-line (1- arg)))) + + (let ((orig-point (point))) + (back-to-indentation) + (when (= orig-point (point)) + (move-beginning-of-line 1)))) + +(global-set-key [remap move-beginning-of-line] + 'prelude-move-beginning-of-line) + (defun prelude-indent-buffer () "Indent the currently visited buffer." (interactive)