diff options
| author | Ravi R Kiran <aine.marina@gmail.com> | 2014-02-03 05:15:13 (GMT) |
|---|---|---|
| committer | Ravikiran Rajagopal <aine.marina@gmail.com> | 2014-02-03 05:15:13 (GMT) |
| commit | 52869ad8f81d890d7b6649dcdd880dab884b437e (patch) | |
| tree | 81ed96560221fb729a92a0b81563e467d6b3842a /ravi-init-navigation.el | |
| parent | 66859ea02e706cbc73c334b77f2b70d67edb1312 (diff) | |
| download | dotemacs-52869ad8f81d890d7b6649dcdd880dab884b437e.zip dotemacs-52869ad8f81d890d7b6649dcdd880dab884b437e.tar.gz dotemacs-52869ad8f81d890d7b6649dcdd880dab884b437e.tar.bz2 | |
Smarter beginning/end-of-line
Diffstat (limited to 'ravi-init-navigation.el')
| -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 |
