Last active
August 5, 2016 18:53
-
-
Save Befzz/22a0d67869cdf23df95158c9446e9494 to your computer and use it in GitHub Desktop.
Emacs forward paragraph with hide-show support
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun ench-is-point-invisible (p) | |
(let ((overlays (overlays-at p)) | |
overlay | |
found) | |
(while overlays | |
(setq overlay (car overlays)) | |
(if (overlay-get overlay 'invisible) | |
(progn | |
(setq found t) | |
(setq overlays)) | |
(setq overlays (cdr overlays)))) | |
found)) | |
(defun ench-forward-empty-line () | |
"Place cursor after next empty line." | |
(interactive) | |
(search-forward-regexp "\n[\t\n ]*\n+[\t ]*" nil "NOERROR" nil) | |
(if (ench-is-point-invisible (point)) | |
(unless (eql (point) (point-max)) | |
(ench-forward-empty-line)) | |
(when (ench-is-point-invisible (- (point) 1)) | |
(ench-forward-empty-line)))) | |
(defun ench-backward-empty-line () | |
"Place cursor before previous empty line." | |
(interactive) | |
(search-backward-regexp "[^ \t\n][\t ]*\n[\n\t ]*\n" nil "NOERROR" nil) | |
(cond | |
((ench-is-point-invisible (point)) | |
(unless (eql (point) (point-min)) | |
(ench-backward-empty-line))) | |
((ench-is-point-invisible (+ (point) 1)) | |
(ench-backward-empty-line)) | |
(t | |
(move-beginning-of-line nil) | |
(back-to-indentation) | |
))) | |
(global-set-key (kbd "<C-up>") 'ench-backward-empty-line) | |
(global-set-key (kbd "<C-down>") 'ench-forward-empty-line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment