org-transclusion icon indicating copy to clipboard operation
org-transclusion copied to clipboard

Suggest to add a hydra interface for org-transclusion.

Open stardiviner opened this issue 2 years ago • 4 comments

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

stardiviner avatar Mar 01 '23 02:03 stardiviner

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...

nobiot avatar Mar 08 '23 21:03 nobiot

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

stardiviner avatar Mar 08 '23 21:03 stardiviner

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

nobiot avatar Apr 23 '23 15:04 nobiot

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.

stardiviner avatar Apr 23 '23 16:04 stardiviner