Anonymous committed 59913d0

* Added back-to-indentation-or-beginning
* Added end-of-code-or-line

Comments (0)

Files changed (2)


+(require 'thingatpt)
 ;; line selection functions
 (defun line-select ()
   "Set the active region to current line"
   (copy-line-with-offset 1))
+(defun back-to-indentation-or-beginning ()
+  (interactive)
+  (if (= (point) (save-excursion (back-to-indentation) (point)))
+      (beginning-of-line)
+    (back-to-indentation)))
+(defun point-in-comment ()
+  "Determine if the point is inside a comment"
+  (interactive)
+  (let ((syn (syntax-ppss)))
+    (and (nth 8 syn)
+         (not (nth 3 syn)))))
+(defun end-of-code-or-line (arg)
+  "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 "P")
+  (let ((eoc (save-excursion
+               (move-end-of-line arg)
+               (while (point-in-comment)
+                 (backward-char))
+               (skip-chars-backward " \t")
+               (point))))
+    (cond ((= (point) eoc)
+           (move-end-of-line arg))
+          (t
+           (move-end-of-line arg)
+           (while (point-in-comment)
+             (backward-char))
+           (skip-chars-backward " \t")))))
 (defun mc/mark-all-like-this-dwim (arg)
   "Uses some sane defaults to guess what the user want to do:
 (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") 'move-end-of-line)
+(global-set-key (kbd "C-e") '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
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.