diff options
| -rw-r--r-- | ravi-init-navigation.el | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/ravi-init-navigation.el b/ravi-init-navigation.el index e22ec4e..d36e3c2 100644 --- a/ravi-init-navigation.el +++ b/ravi-init-navigation.el @@ -148,6 +148,40 @@ ;; C-: duplicates line, C-u C-: comments first line (bind-key "C-:" 'ravi/kyle-sherman-duplicate-line) +(defun ravi/back-to-indentation-or-beginning () (interactive) + (if (= (point) (progn (back-to-indentation) (point))) + (beginning-of-line))) +(bind-key "C-a" 'ravi/back-to-indentation-or-beginning) + +(defun ravi/Fuco-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 ravi/Fuco-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 (ravi/Fuco-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 (ravi/Fuco-point-in-comment) + (backward-char)) + (skip-chars-backward " \t"))))) +(bind-key "C-e" 'ravi/Fuco-end-of-code-or-line+) + ;; Use current line for region-based commands if no region selected (use-package whole-line-or-region :config |
