(let ((map (make-sparse-keymap)))
(outline-minor-mode-cycle--bind map (kbd "TAB") #'outline-cycle)
(outline-minor-mode-cycle--bind map (kbd "<backtab>") #'outline-cycle-buffer)
- (keymap-set map "<left-margin> <mouse-1>" 'outline-cycle)
- (keymap-set map "<right-margin> <mouse-1>" 'outline-cycle)
- (keymap-set map "<left-margin> S-<mouse-1>" 'outline-cycle-buffer)
- (keymap-set map "<right-margin> S-<mouse-1>" 'outline-cycle-buffer)
+ (keymap-set map "<left-margin> <mouse-1>" #'outline-cycle)
+ (keymap-set map "<right-margin> <mouse-1>" #'outline-cycle)
+ (keymap-set map "<left-margin> S-<mouse-1>" #'outline-cycle-buffer)
+ (keymap-set map "<right-margin> S-<mouse-1>" #'outline-cycle-buffer)
map)
"Keymap used as a parent of the `outline-minor-mode' keymap.
It contains key bindings that can be used to cycle visibility.
The value of this variable is checked as part of loading Outline mode.
After that, changing the prefix key requires manipulating keymaps."
:type 'key-sequence
- :initialize 'custom-initialize-default
+ :initialize #'custom-initialize-default
:set (lambda (sym val)
(define-key outline-minor-mode-map outline-minor-mode-prefix nil)
(define-key outline-minor-mode-map val outline-mode-prefix-map)
(goto-char (match-beginning 0))
;; Compensate "\n" from the beginning of regexp
(when (and outline-search-function (not (bobp))) (forward-char -1)))
+ ;; FIXME: Use `outline--end-of-previous'.
(when (and (bolp) (or outline-blank-line (eobp)) (not (bobp)))
(forward-char -1)))
(progn (outline-end-of-subtree) (point))
flag)))
+(defun outline--end-of-previous ()
+ "Go back from BOH (or EOB) to end of previous element."
+ (if (eobp)
+ (if (bolp) (forward-char -1))
+ ;; Go to end of line before heading
+ (forward-char -1)
+ (if (and outline-blank-line (bolp))
+ ;; leave blank line before heading
+ (forward-char -1))))
+
(defun outline-end-of-subtree ()
"Move to the end of the current subtree."
(outline-back-to-heading)
(outline-next-heading))
(if (and (bolp) (not (eolp)))
;; We stopped at a nonempty line (the next heading).
- (progn
- ;; Go to end of line before heading
- (forward-char -1)
- (if (and outline-blank-line (bolp))
- ;; leave blank line before heading
- (forward-char -1))))))
+ (outline--end-of-previous))))
\f
(defun outline-show-branches ()
"Show all subheadings of this heading, but not their bodies."
(run-hooks 'outline-view-change-hook))
(defun outline--hidden-headings-paths ()
- "Return a hash with headings of currently hidden outlines.
-Every hash key is a list whose elements compose a complete path
+ "Return (HASH-TABLE CURRENT-HEADING).
+HASH-TABLE holds the headings of currently hidden outlines.
+Every key is a list whose elements compose a complete path
of headings descending from the top level down to the bottom level.
+Every entry's value is non-nil if that entry should be hidden.
+The specific non-nil vale can be t to hide just the entry, or a number
+LEVEL to mean that not just the entry should be hidden but also all the
+subsequent elements of level higher or equal to LEVEL.
This is useful to save the hidden outlines and restore them later
-after reverting the buffer. Also return the outline where point
-was located before reverting the buffer."
+after reverting the buffer.
+CURRENT-HEADING is the heading where point is located."
(let* ((paths (make-hash-table :test #'equal))
path current-path
(current-heading-p (outline-on-heading-p))
(current-end (when current-heading-p (pos-eol))))
(outline-map-region
(lambda ()
- (let* ((level (funcall outline-level))
- (heading (buffer-substring-no-properties (pos-bol) (pos-eol))))
- (while (and path (>= (cdar path) level))
- (pop path))
- (push (cons heading level) path)
- (when (save-excursion
- (outline-end-of-heading)
- (seq-some (lambda (o) (eq (overlay-get o 'invisible)
- 'outline))
- (overlays-at (point))))
- (setf (gethash (mapcar #'car path) paths) t))
+ (let ((level (funcall outline-level)))
+ (if (outline-invisible-p)
+ ;; Covered by "the" previous heading.
+ (cl-callf (lambda (l) (if (numberp l) (min l level) level))
+ (gethash (mapcar #'car path) paths))
+ (let ((heading (buffer-substring-no-properties (pos-bol) (pos-eol))))
+ (while (and path (>= (cdar path) level))
+ (pop path))
+ (push (cons heading level) path)
+ (when (save-excursion
+ (outline-end-of-heading)
+ (outline-invisible-p))
+ (setf (gethash (mapcar #'car path) paths) t))))
(when (and current-heading-p (<= current-beg (point) current-end))
(setq current-path (mapcar #'car path)))))
(point-min) (point-max))
(list paths current-path)))
(defun outline--hidden-headings-restore-paths (paths current-path)
- "Restore hidden outlines from a hash of hidden headings.
+ "Restore hidden outlines from a hash-table of hidden headings.
This is useful after reverting the buffer to restore the outlines
hidden by `outline--hidden-headings-paths'. Also restore point
on the same outline where point was before reverting the buffer."
- (let (path current-point outline-view-change-hook)
+ (let ((hidelevel nil) (hidestart nil)
+ path current-point outline-view-change-hook)
(outline-map-region
(lambda ()
- (let* ((level (funcall outline-level))
- (heading (buffer-substring (pos-bol) (pos-eol))))
- (while (and path (>= (cdar path) level))
- (pop path))
- (push (cons heading level) path)
- (when (gethash (mapcar #'car path) paths)
- (outline-hide-subtree))
+ (let ((level (funcall outline-level)))
+ (if (and (numberp hidelevel) (<= hidelevel level))
+ nil
+ (when hidestart
+ (outline-flag-region hidestart
+ (save-excursion (outline--end-of-previous)
+ (point))
+ t)
+ (setq hidestart nil))
+ (let* ((heading (buffer-substring-no-properties
+ (pos-bol) (pos-eol))))
+ (while (and path (>= (cdar path) level))
+ (pop path))
+ (push (cons heading level) path)
+ (when (setq hidelevel (gethash (mapcar #'car path) paths))
+ (setq hidestart (save-excursion (outline-end-of-heading)
+ (point))))))
(when (and current-path (equal current-path (mapcar #'car path)))
(setq current-point (point)))))
(point-min) (point-max))
+ (when hidestart
+ (outline-flag-region hidestart
+ (save-excursion
+ (goto-char (point-max))
+ (outline--end-of-previous)
+ (point))
+ t))
(when current-point (goto-char current-point))))
(defun outline-revert-buffer-restore-visibility ()
(transient--emergency-exit :debugger)
(apply #'debug args))
-;;; Options
+;;;; Options
(defgroup transient nil
"Transient commands."
:group 'transient
:type 'boolean)
-;;; Faces
+;;;; Faces
(defgroup transient-faces nil
"Faces used by Transient."
See also option `transient-highlight-mismatched-keys'."
:group 'transient-faces)
-;;; Persistence
+;;;; Persistence
(defun transient--read-file-contents (file)
(with-demoted-errors "Transient error: %S"
(unless noninteractive
(add-hook 'kill-emacs-hook #'transient-maybe-save-history))
-;;; Classes
+;;;; Classes
;;;; Prefix
(defclass transient-prefix ()
subgroups. The subgroups are responsible for displaying their
elements themselves.")
-;;; Define
+;;;; Define
(defmacro transient-define-prefix (name arglist &rest args)
"Define NAME as a transient prefix command.
(setq prefix (oref prefix command)))
(mapcar (apply-partially #'transient-parse-suffix prefix) suffixes))
-;;; Edit
+;;;; Edit
(defun transient--insert-suffix (prefix loc suffix action &optional keep-other)
(pcase-let* ((suf (cl-etypecase suffix
(user-error "Cannot set level for `%s'; no prototype object exists"
command)))
-;;; Variables
+;;;; Variables
(defvar transient-current-prefix nil
"The transient from which this suffix command was invoked.
mwheel-scroll
scroll-bar-toolkit-scroll))
-;;; Identities
+;;;; Identities
(defun transient-active-prefix (&optional prefixes)
"Return the active transient object.
(seq-some (lambda (cmd) (get cmd 'transient--suffix))
(function-alias-p command))))
-;;; Keymaps
+;;;; Keymaps
(defvar-keymap transient-base-map
:doc "Parent of other keymaps used by Transient.
transient--transient-map))
topmap))
-;;; Setup
+;;;; Setup
(defun transient-setup (&optional name layout edit &rest params)
"Setup the transient specified by NAME.
(transient--debug " autoload %s" cmd)
(autoload-do-load fn)))
-;;; Flow-Control
+;;;; Flow-Control
(defun transient--setup-transient ()
(transient--debug 'setup-transient)
(transient--pre-exit)
(transient--post-exit this-command)))
-;;; Pre-Commands
+;;;; Pre-Commands
(defun transient--call-pre-command ()
(if-let* ((fn (transient--get-pre-command this-command
(put 'transient--do-move 'transient-face 'transient-key-stay)
(put 'transient--do-minus 'transient-face 'transient-key-stay)
-;;; Commands
+;;;; Commands
;;;; Noop
(defun transient-noop ()
arguments " "))
(message "%s: %S" (key-description (this-command-keys)) arguments)))
-;;; Value
+;;;; Value
;;;; Init
(cl-defgeneric transient-init-value (obj)
(or (match-string 1 match) "")))
(and (member arg args) t)))
-;;; Return
+;;;; Return
(defun transient-init-return (obj)
(when-let* ((transient--stack)
(list t 'recurse #'transient--do-recurse))))
(oset obj return t)))
-;;; Scope
+;;;; Scope
;;;; Init
(cl-defgeneric transient-init-scope (obj)
(and-let* ((obj (transient-prefix-object)))
(oref obj scope))))
-;;; History
+;;;; History
(cl-defgeneric transient--history-key (obj)
"Return OBJ's history key.")
(cons val (delete val (alist-get (transient--history-key obj)
transient-history))))))
-;;; Display
+;;;; Display
(defun transient--show-hint ()
(let ((message-log-max nil))
(window-body-width window t)
(window-body-height window t))))
-;;; Delete
+;;;; Delete
(defun transient--delete-window ()
(when (window-live-p transient--window)
(setq show (natnump show)))
show))
-;;; Format
+;;;; Format
(defun transient--format-hint ()
(if (and transient-show-popup (<= transient-show-popup 0))
(propertize (car (split-string doc "\n")) 'face 'font-lock-doc-face)
(propertize (symbol-name command) 'face 'font-lock-function-name-face))))
-;;; Help
+;;;; Help
(cl-defgeneric transient-show-help (obj)
"Show documentation for the command represented by OBJ.")
(setq lists (mapcar #'cdr lists)))
(nreverse result)))
-;;; Font-Lock
+;;;; Font-Lock
(defconst transient-font-lock-keywords
(eval-when-compile
(font-lock-add-keywords 'emacs-lisp-mode transient-font-lock-keywords)
-;;; Auxiliary Classes
+;;;; Auxiliary Classes
;;;; `transient-lisp-variable'
(defclass transient-lisp-variable (transient-variable)
;; indent-tabs-mode: nil
;; checkdoc-symbol-words: ("command-line" "edit-mode" "help-mode")
;; End:
-;;; transient.el ends here
+;;;; transient.el ends here