emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Juan Manuel Macías" <maciaschain@posteo.net>
To: orgmode <emacs-orgmode@gnu.org>
Subject: [Tip] Popup-menu with several actions for a link
Date: Fri, 18 Aug 2023 18:27:01 +0000	[thread overview]
Message-ID: <87ttsww6iy.fsf@posteo.net> (raw)

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	other threads:[~2023-08-18 18:28 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-18 18:27 Juan Manuel Macías [this message]
2023-08-19 19:53 ` [Tip] Popup-menu with several actions for a link Ihor Radchenko
2023-08-19 20:29   ` Juan Manuel Macías
2023-08-20  7:23     ` Ihor Radchenko
2023-08-20 10:13       ` Juan Manuel Macías

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ttsww6iy.fsf@posteo.net \
    --to=maciaschain@posteo.net \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).