emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/embark 203f4f2 01/11: Add heading target and keymap bas


From: ELPA Syncer
Subject: [elpa] externals/embark 203f4f2 01/11: Add heading target and keymap based on outline mode
Date: Thu, 9 Dec 2021 17:57:24 -0500 (EST)

branch: externals/embark
commit 203f4f22eedef10bcf80b9e3c6372daede095ac7
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>

    Add heading target and keymap based on outline mode
    
    We could also reuse the outline-mode-prefix-map directly instead of the
    embark-heading-map. However Embark mostly uses keys without modifiers.
---
 embark.el | 37 +++++++++++++++++++++++++++++++++++--
 1 file changed, 35 insertions(+), 2 deletions(-)

diff --git a/embark.el b/embark.el
index bd0d7c6..128d34d 100644
--- a/embark.el
+++ b/embark.el
@@ -139,6 +139,7 @@
     (sentence . embark-sentence-map)
     (paragraph . embark-paragraph-map)
     (kill-ring . embark-kill-ring-map)
+    (heading . embark-heading-map)
     (t . embark-general-map))
   "Alist of action types and corresponding keymaps.
 For any type not listed here, `embark-act' will use
@@ -161,7 +162,8 @@ For any type not listed here, `embark-act' will use
     embark-target-expression-at-point
     embark-target-sentence-at-point
     embark-target-paragraph-at-point
-    embark-target-defun-at-point)
+    embark-target-defun-at-point
+    embark-target-heading-at-point)
   "List of functions to determine the target in current context.
 Each function should take no arguments and return either nil to
 indicate that no target has been found, a cons (type . target)
@@ -499,6 +501,9 @@ arguments and more details."
 (defcustom embark-repeat-actions
   '(embark-next-symbol embark-previous-symbol backward-up-list
     backward-list forward-list forward-sexp backward-sexp mark
+    outline-next-visible-heading outline-previous-visible-heading
+    outline-up-heading outline-forward-same-level outline-backward-same-level
+    outline-show-subtree outline-hide-subtree outline-cycle
     transpose-sexps transpose-sentences transpose-paragraphs
     forward-sentence backward-sentence forward-paragraph
     backward-paragraph)
@@ -822,6 +827,16 @@ As a convenience, in Org Mode an initial ' or surrounding 
== or
         ,name
         . ,bounds))))
 
+(defun embark-target-heading-at-point ()
+  "Target the outline heading at point."
+  (let ((beg (line-beginning-position))
+        (end (line-end-position)))
+    (when (save-excursion
+            (goto-char beg)
+            (and (bolp) (looking-at outline-regexp)))
+      (require 'outline) ;; Ensure that outline commands are available
+      `(heading ,(buffer-substring-no-properties beg end) ,beg . ,end))))
+
 (defun embark-target-top-minibuffer-completion ()
   "Target the top completion candidate in the minibuffer.
 Return the category metadatum as the type of the target.
@@ -3584,6 +3599,24 @@ and leaves the point to the left of it."
   ("o" checkdoc-defun)
   ("N" narrow-to-defun))
 
+;; Use quoted symbols to avoid bytecompiler warnings.
+(embark-define-keymap embark-heading-map
+  "Keymap for Embark heading actions."
+  ("RET" 'outline-show-subtree)
+  ("TAB" 'outline-cycle) ;; New in Emacs 28!
+  ("SPC" 'outline-mark-subtree)
+  ("n" 'outline-next-visible-heading)
+  ("p" 'outline-previous-visible-heading)
+  ("f" 'outline-forward-same-level)
+  ("b" 'outline-backward-same-level)
+  ("^" 'outline-move-subtree-up)
+  ("v" 'outline-move-subtree-down)
+  ("u" 'outline-up-heading)
+  ("s" 'outline-show-subtree)
+  ("d" 'outline-hide-subtree)
+  (">" 'outline-demote)
+  ("<" 'outline-promote))
+
 (embark-define-keymap embark-symbol-map
   "Keymap for Embark symbol actions."
   :parent embark-identifier-map
@@ -3712,7 +3745,7 @@ and leaves the point to the left of it."
   ("p" project-find-file)
   ("r" recentf-open-files)
   ("b" switch-to-buffer)
-  ("4b" switch-to-buffer-other-window)  
+  ("4b" switch-to-buffer-other-window)
   ("l" locate)
   ("L" find-library))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]