Skip to content

Instantly share code, notes, and snippets.

@Befzz
Last active August 5, 2016 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Befzz/22a0d67869cdf23df95158c9446e9494 to your computer and use it in GitHub Desktop.
Save Befzz/22a0d67869cdf23df95158c9446e9494 to your computer and use it in GitHub Desktop.
Emacs forward paragraph with hide-show support
(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