emacs-orgmode
[Top][All Lists]
Advanced

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

[Tip] Popup-menu with several actions for a link


From: Juan Manuel Macías
Subject: [Tip] Popup-menu with several actions for a link
Date: Fri, 18 Aug 2023 18:27:01 +0000

Hi,

I’ve been experimenting for a while with the popup.el library
(<https://github.com/auto-complete/popup-el>), which offers an easy way
to create popup menus (even cascading menus), with auto-completion
functions. I’m sharing here a popup menu that I’ve defined to perform
various actions on an Org link, in case anyone finds it useful.

In this list I store the functions that I am writing to manipulate links
(open the link with eww, open the file with an external application,
attach it to an email, upload it to Imgur, copy it to another directory
or move it, visit the file directory, etc.). Something like this:

┌────
│ (setq my-org-link-actions-list
│       '(("Action 1" . function1)
│         ("Action 2" . function2)
│         ("etc..." . etc)))
└────

Then, I have defined this popup-menu that is displayed on a link:

┌────
│ (defun my-org-actions-link-popup ()
│     (interactive)
│     (funcall
│      (popup-menu*
│       (mapcar
│        (lambda (x)
│        (popup-make-item (car x) :value (cdr x)))
│        my-org-link-actions-list)
│       :isearch t)))
└────

And a little addendum. Being a Hyperbole user, it occurred to me a while
ago that a ’secondary action key’ could be very useful to me in certain
contexts. So I defined this:

┌────
│ (defvar my-hyp-alt-act nil)
│ 
│ (defun my-hyp-action-key-alt ()
│   (interactive)
│   (let ((my-hyp-alt-act t))
│     (action-key)))
└────

If `C-c i' is for the ’primary’ action key, `C-c I' is for the
’secondary’ action:

┌────
│ (global-set-key (kbd "C-c I") #'mi-hyp-action-key-alt)
└────

And then I’ve modified hyperbole `org-link' a bit:

┌────
│ (defact org-link (&optional link)
│   "Follows an optional Org mode LINK to its target.
│ If LINK is nil, follows any link at point.  Otherwise, triggers an error."
│   (if (not my-hyp-alt-act)
│       (if (stringp link)
│         (org-link-open-from-string link)
│       (org-open-at-point))
│     (hact #'my-org-actions-link-popup)))
└────

In this way, if I have the point over the link and press `C-c i', the
link opens. If I press `C-c I' the popup-menu is displayed.

Best regards,

Juan Manuel 

-- 
--
------------------------------------------------------
Juan Manuel Macías 

https://juanmanuelmacias.com

https://lunotipia.juanmanuelmacias.com

https://gnutas.juanmanuelmacias.com




reply via email to

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