nobiot / org-transclusion

Emacs package to enable transclusion with Org Mode
https://nobiot.github.io/org-transclusion/
GNU General Public License v3.0
917 stars 44 forks source link

Suggest to add a hydra interface for org-transclusion. #169

Open stardiviner opened 1 year ago

stardiviner commented 1 year ago

Sometimes I will forget org-transclusion property keywords, I have to lookup document again. So I hope org-transclusion can provide an interface which contains all property keywords.

Here is my own config for your reference.

(require 'hydra)

  (defmacro hydra-org-transclusion--detect-transclude-at-point-wrapper (body)
    `(let ((line-text (buffer-substring-no-properties
                       (line-beginning-position) (line-end-position)))
           (position (point))
           (end-of-line (line-end-position)))
       (if (string-match-p "#\\+transclude:" line-text)
           (progn
             (unless (eq position end-of-line) (end-of-line))
             (insert " ")
             ,body)
         (user-error "You'r not on #+transclude: [[link]] line."))))

(defhydra hydra-org-transclusion (:color "blue" :hint nil :exit nil)
    "
^Toggle status^                                ^Options^
^---------------^                              ^--------------------^
_m_: toggle minor Mode                         _l_: :level N
_p_: add transclude #+transclude at Point.     _o_: :only-contents
_a_: add ALL transclusions in current buffer.  _e_: :expand-links
"
    ("m" org-transclusion-mode :color black)
    ("p" org-transclusion-add :color blue)
    ("a" org-transclusion-add-all :color blue)
    ("l" (lambda ()
           (interactive)
           (hydra-org-transclusion--detect-transclude-at-point-wrapper
            (insert (format ":level %s"
                            (read-string "Set org-transclusion content headline level: ")))))
     :color green)
    ("o" (lambda ()
           (interactive)
           (hydra-org-transclusion--detect-transclude-at-point-wrapper
            (insert ":only-contents")))
     :color green)
    ("e" (lambda ()
           (interactive)
           (hydra-org-transclusion--detect-transclude-at-point-wrapper
            (insert ":expand-links")))
     :color green)
    )

  (define-key org-mode-map (kbd "C-c o l") 'hydra-org-transclusion/body)

Here is the screenshot:

CleanShot 2023-03-01 at 10 05 16@2x

nobiot commented 1 year ago

Thank you for your suggestion and code! I agree with you on the point that UX for the optional props should be improved.

I have an idea that I'd like to explore a bit. I do not have enough bandwidth at the moment but I'd like to give it a shot when I have a bit of breathing space. The idea is simple and goes like this:

  1. Create a set of functions, each of which handles adding/removing a property to the #+transclude: keyword
  2. These can be added to keybinding

At the moment, you are using lambda functions in your Hydra configuration. And you could replace them with the functions.

This way, it does not have to be Hydra. I guess it can be Transient, Which-key, or the built-in menu system.

Perhaps I could borrow the code you did for the lambda functions...

stardiviner commented 1 year ago

Indeed, your idea is better and improved. Added into wishlist now.

nobiot commented 1 year ago

Exploring the aforementioned idea in PR #185. If @stardiviner or anyone has time to comment, that will be much appreciated. Thank you.

stardiviner commented 1 year ago

Exploring the aforementioned idea in PR #185. If @stardiviner or anyone has time to comment, that will be much appreciated. Thank you.

I reviewed the PR and commented.