Commits

Anonymous committed 88c0a27

Consolidated C-a/C-e functions into a single definition for each

Comments (0)

Files changed (2)

files/defuns-edit.el

   (set-mark (point))
   (end-of-line))
 
+;; TODO: if inside a comment, on enter should continue with comment
+;; (call indent-new-comment-line was M-j)... or is this really useful?
 (defun open-next-line ()
   "Instead of going to the beginning of line, autoindent according
 to the active mode"
   (interactive)
   (copy-line-with-offset 1))
 
-(defun back-to-indentation-or-beginning ()
-  (interactive)
-  (if (= (point) (save-excursion (back-to-indentation-logical-or-visual) (point)))
-      (beginning-of-line-logical-or-visual)
-    (back-to-indentation-logical-or-visual)))
-
 (defun point-in-comment ()
   "Determine if the point is inside a comment"
   (interactive)
     (or (eq 'font-lock-comment-face face)
         (eq 'font-lock-comment-delimiter-face face))))
 
-(defun back-to-visual-indentation ()
-  "Move point to the first non-whitespace character on this visual line."
+(defun my-back-to-indentation-or-beginning ()
+  "Jump back to indentation of the current line.  If already
+there, jump to the beginning of current line.  If visual mode is
+enabled, move according to the visual lines."
   (interactive)
+  (flet ((my-back-to-indentation
+          ()
+          (if (visual-line-mode)
+              (flet ((beginning-of-line (arg) (beginning-of-visual-line arg)))
+                (back-to-indentation))
+            (back-to-indentation))))
+    (if (= (point) (save-excursion
+                     (my-back-to-indentation)
+                     (point)))
+        (if (visual-line-mode)
+            (beginning-of-visual-line)
+          (move-beginning-of-line))
+      (my-back-to-indentation))))
+
+(defun my-end-of-code-or-line ()
+  "Move to the end of code.  If already there, move to the end of line,
+that is after the possible comment.  If at the end of line, move
+to the end of code.
+
+Example:
+  (serious |code here)1 ;; useless commend2
+
+In the example, | is the current point, 1 is the position of
+point after one invocation of this funciton, 2 is position after
+repeated invocation. On subsequent calls the point jumps between
+1 and 2.
+
+Comments are recognized in any mode that sets syntax-ppss
+properly."
   (interactive)
-  (beginning-of-visual-line)
-  (skip-syntax-forward " " (line-end-position))
-  (backward-prefix-chars))
-
-(defun back-to-indentation-logical-or-visual ()
-  "Move back to logical or visual indentation."
-  (interactive)
-  (if (visual-line-mode) (back-to-visual-indentation) (back-to-indentation)))
-
-(defun end-of-line-logical-or-visual ()
-  "Move to the end of visual line if visual mode is enabled
-   or to the logical end otherwise."
-  (interactive)
-  (if (visual-line-mode) (end-of-visual-line) (move-end-of-line)))
-
-(defun beginning-of-line-logical-or-visual ()
-  "Move to the beginning of visual line if visual mode is enabled
-   or logical beginning otherwise"
-  (interactive)
-  (if (visual-line-mode) (beginning-of-visual-line) (move-beginning-of-line)))
-
-(defun end-of-code-or-line ()
-  "Move to the end of code. If already there, move to the end of line,
-that is after the possible comment. If at the end of line, move to the
-end of code.
-
-Comments are recognized in any mode that sets syntax-ppss properly."
-  (interactive)
-  (let ((eoc (save-excursion
-               (end-of-line-logical-or-visual)
-               (while (and (point-in-comment)
-                           (not (bolp))
-                           (> (point) 1))
-                 (backward-char))
-               (skip-chars-backward " \t")
-               (point))))
-    (cond ((= (point) eoc)
-           (end-of-line-logical-or-visual))
-          (t
-           (goto-char eoc)))))
+  (flet ((end-of-line-lov () (if (visual-line-mode)
+                                 (end-of-visual-line)
+                               (move-end-of-line)))
+         (beg-of-line-lov () (if (visual-line-mode)
+                                 (beginning-of-visual-line)
+                               (move-beginning-of-line))))
+    (let ((eoc (save-excursion
+                 (end-of-line-lov)
+                 (while (and (point-in-comment)
+                             (not (bolp)))
+                   (backward-char))
+                 (skip-syntax-backward " ")
+                 ;; if we skipped all the way to the beginning, that
+                 ;; means there's only comment on this line, so this
+                 ;; should just jump to the end.
+                 (if (= (point) (save-excursion
+                                  (beg-of-line-lov)
+                                  (point)))
+                     (progn (end-of-line-lov)
+                            (point))
+                   (point)))))
+      (if (= (point) eoc)
+          (end-of-line-lov)
+        (goto-char eoc)))))
 
 (defun mc/mark-all-like-this-dwim (arg)
   "Uses some sane defaults to guess what the user want to do:
 (global-unset-key (kbd "M-m"))
 (global-unset-key (kbd "C-a"))
 (global-set-key (kbd "M-m") 'move-beginning-of-line)
-(global-set-key (kbd "C-a") 'back-to-indentation-or-beginning)
-(global-set-key (kbd "C-e") 'end-of-code-or-line)
+(global-set-key (kbd "C-a") 'my-back-to-indentation-or-beginning)
+(global-set-key (kbd "C-e") 'my-end-of-code-or-line)
 ;; buffer
 (global-unset-key [(home)]) ;; was C-a
 (global-unset-key [(end)]) ;; was C-e
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.