]> git.bundesbrandschatzamt.de Git - emacsconfig.git/commitdiff
- C-a by indentation
authorAndreas Gerler <baronNOSPAMbundesbrandschatzamt.de>
Fri, 11 Mar 2016 12:31:48 +0000 (13:31 +0100)
committerAndreas Gerler <baronNOSPAMbundesbrandschatzamt.de>
Fri, 11 Mar 2016 12:31:48 +0000 (13:31 +0100)
borrowed from https://github.com/Wilfred/.emacs.d

bba.org

diff --git a/bba.org b/bba.org
index f33971a8a312c4cfe661ab6131bda32a66ca0a12..eb375d686f34336c1a9dce45e2de67a54d995c65 100644 (file)
--- a/bba.org
+++ b/bba.org
@@ -2359,6 +2359,32 @@ we use that as default:
   (global-set-key (kbd "C-M-r") 'isearch-backward)
 #+END_SRC
 
+* By indentation
+
+Borrowed from [[https://github.com/Wilfred/.emacs.d][github]]:
+
+[[elisp:(describe-key%20(kbd%20"C-a"))][C-a]] normally moves us to the beginning of the line unconditionally
+with [[elisp:(describe-function%20#'move-beginning-of-line)][move-beginning-of-line]]. This version is more useful, as it moves
+to the first non-whitespace character if we're already at the
+beginning of the line. Repeated use of `C-a' toggles between these two
+positions.
+
+#+BEGIN_SRC emacs-lisp :tangle yes
+  (defun beginning-of-line-dwim ()
+    "Toggles between moving point to the first non-whitespace character, and
+  the start of the line."
+    (interactive)
+    (let ((start-position (point)))
+      ;; Move to the first non-whitespace character.
+      (back-to-indentation)
+
+      ;; If we haven't moved position, go to start of the line.
+      (when (= (point) start-position)
+        (move-beginning-of-line nil))))
+
+  (global-set-key (kbd "C-a") 'beginning-of-line-dwim)
+#+END_SRC
+
 * Beautifying JSON
 
 #+BEGIN_SRC emacs-lisp