New editor/fold module
Extracted from feature/evil and emacs/hideshow.
This commit is contained in:
parent
e0519098d9
commit
7d0caf3efd
11 changed files with 169 additions and 137 deletions
|
@ -1,87 +0,0 @@
|
|||
;;; emacs/hideshow/autoload.el -*- lexical-binding: t; -*-
|
||||
|
||||
(defface +hideshow-folded-face
|
||||
`((t (:inherit font-lock-comment-face :weight light)))
|
||||
"Face to hightlight `hideshow' overlays."
|
||||
:group 'doom-themes)
|
||||
|
||||
;;;###autoload
|
||||
(defun +hideshow*ensure-mode (&rest _)
|
||||
"Ensure hs-minor-mode is enabled."
|
||||
(unless (bound-and-true-p hs-minor-mode)
|
||||
(hs-minor-mode +1)))
|
||||
|
||||
;;;###autoload
|
||||
(defun +hideshow-haml-forward-sexp (arg)
|
||||
(haml-forward-sexp arg)
|
||||
(move-beginning-of-line 1))
|
||||
|
||||
;;;###autoload
|
||||
(defun +hideshow-forward-block-by-indent (_arg)
|
||||
(let ((start (current-indentation)))
|
||||
(forward-line)
|
||||
(unless (= start (current-indentation))
|
||||
(let ((range (+hideshow-indent-range)))
|
||||
(goto-char (cadr range))
|
||||
(end-of-line)))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +hideshow-set-up-overlay (ov)
|
||||
(when (eq 'code (overlay-get ov 'hs))
|
||||
(when (featurep 'vimish-fold)
|
||||
(overlay-put
|
||||
ov 'before-string
|
||||
(propertize "…" 'display
|
||||
(list vimish-fold-indication-mode
|
||||
'empty-line
|
||||
'vimish-fold-fringe))))
|
||||
(overlay-put
|
||||
ov 'display (propertize " [...] " 'face '+hideshow-folded-face))))
|
||||
|
||||
|
||||
;;
|
||||
;; Indentation detection
|
||||
|
||||
(defun +hideshow--empty-line-p ()
|
||||
(string= "" (string-trim (thing-at-point 'line))))
|
||||
|
||||
(defun +hideshow--geq-or-empty-p ()
|
||||
(or (+hideshow--empty-line-p) (>= (current-indentation) base)))
|
||||
|
||||
(defun +hideshow--g-or-empty-p ()
|
||||
(or (+hideshow--empty-line-p) (> (current-indentation) base)))
|
||||
|
||||
(defun +hideshow--seek (start direction before skip predicate)
|
||||
"Seeks forward (if direction is 1) or backward (if direction is -1) from start, until predicate
|
||||
fails. If before is nil, it will return the first line where predicate fails, otherwise it returns
|
||||
the last line where predicate holds."
|
||||
(save-excursion
|
||||
(goto-char start)
|
||||
(goto-char (point-at-bol))
|
||||
(let ((bnd (if (> 0 direction)
|
||||
(point-min)
|
||||
(point-max)))
|
||||
(pt (point)))
|
||||
(when skip (forward-line direction))
|
||||
(cl-loop while (and (/= (point) bnd) (funcall predicate))
|
||||
do (progn
|
||||
(when before (setq pt (point-at-bol)))
|
||||
(forward-line direction)
|
||||
(unless before (setq pt (point-at-bol)))))
|
||||
pt)))
|
||||
|
||||
(defun +hideshow-indent-range (&optional point)
|
||||
"Return the point at the begin and end of the text block with the same (or
|
||||
greater) indentation. If `point' is supplied and non-nil it will return the
|
||||
begin and end of the block surrounding point."
|
||||
(save-excursion
|
||||
(when point
|
||||
(goto-char point))
|
||||
(let ((base (current-indentation))
|
||||
(begin (point))
|
||||
(end (point)))
|
||||
(setq begin (+hideshow--seek begin -1 t nil #'+hideshow--geq-or-empty-p)
|
||||
begin (+hideshow--seek begin 1 nil nil #'+hideshow--g-or-empty-p)
|
||||
end (+hideshow--seek end 1 t nil #'+hideshow--geq-or-empty-p)
|
||||
end (+hideshow--seek end -1 nil nil #'+hideshow--empty-line-p))
|
||||
(list begin end base))))
|
|
@ -1,38 +0,0 @@
|
|||
;;; emacs/hideshow/config.el -*- lexical-binding: t; -*-
|
||||
|
||||
(after! hideshow ; built-in
|
||||
(setq hs-hide-comments-when-hiding-all nil
|
||||
;; Nicer code-folding overlays (with fringe indicators)
|
||||
hs-set-up-overlay #'+hideshow-set-up-overlay)
|
||||
|
||||
;; extra folding support for more languages
|
||||
(unless (assq 't hs-special-modes-alist)
|
||||
(setq hs-special-modes-alist
|
||||
(append
|
||||
'((vimrc-mode "{{{" "}}}" "\"")
|
||||
(yaml-mode "\\s-*\\_<\\(?:[^:]+\\)\\_>"
|
||||
""
|
||||
"#"
|
||||
+hideshow-forward-block-by-indent nil)
|
||||
(haml-mode "[#.%]" "\n" "/" +hideshow-haml-forward-sexp nil)
|
||||
(ruby-mode "class\\|d\\(?:ef\\|o\\)\\|module\\|[[{]"
|
||||
"end\\|[]}]"
|
||||
"#\\|=begin"
|
||||
ruby-forward-sexp)
|
||||
(enh-ruby-mode "class\\|d\\(?:ef\\|o\\)\\|module\\|[[{]"
|
||||
"end\\|[]}]"
|
||||
"#\\|=begin"
|
||||
enh-ruby-forward-sexp nil)
|
||||
(matlab-mode "if\\|switch\\|case\\|otherwise\\|while\\|for\\|try\\|catch"
|
||||
"end"
|
||||
nil (lambda (_arg) (matlab-forward-sexp))))
|
||||
hs-special-modes-alist
|
||||
'((t))))))
|
||||
|
||||
|
||||
;; Ensure `hs-minor-mode' is active when triggering these commands
|
||||
(advice-add #'hs-toggle-hiding :before #'+hideshow*ensure-mode)
|
||||
(advice-add #'hs-hide-block :before #'+hideshow*ensure-mode)
|
||||
(advice-add #'hs-hide-level :before #'+hideshow*ensure-mode)
|
||||
(advice-add #'hs-show-all :before #'+hideshow*ensure-mode)
|
||||
(advice-add #'hs-hide-all :before #'+hideshow*ensure-mode)
|
Loading…
Add table
Add a link
Reference in a new issue