all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [Tip] Popup-menu with several actions for a link
@ 2023-08-18 18:27 Juan Manuel Macías
  2023-08-19 19:53 ` Ihor Radchenko
  0 siblings, 1 reply; 5+ messages in thread
From: Juan Manuel Macías @ 2023-08-18 18:27 UTC (permalink / raw)
  To: orgmode

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



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Tip] Popup-menu with several actions for a link
  2023-08-18 18:27 [Tip] Popup-menu with several actions for a link Juan Manuel Macías
@ 2023-08-19 19:53 ` Ihor Radchenko
  2023-08-19 20:29   ` Juan Manuel Macías
  0 siblings, 1 reply; 5+ messages in thread
From: Ihor Radchenko @ 2023-08-19 19:53 UTC (permalink / raw)
  To: Juan Manuel Macías; +Cc: orgmode

Juan Manuel Macías <maciaschain@posteo.net> writes:

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

Since Emacs 28, Emacs has built-in context menu. (terminal is also
supported) Moreover, major modes are encouraged to add support for
context menus.

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

May you explain more about how you attach to an email/upload?

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Tip] Popup-menu with several actions for a link
  2023-08-19 19:53 ` Ihor Radchenko
@ 2023-08-19 20:29   ` Juan Manuel Macías
  2023-08-20  7:23     ` Ihor Radchenko
  0 siblings, 1 reply; 5+ messages in thread
From: Juan Manuel Macías @ 2023-08-19 20:29 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: orgmode

Ihor Radchenko writes:

>> 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.
>
> Since Emacs 28, Emacs has built-in context menu. (terminal is also
> supported) Moreover, major modes are encouraged to add support for
> context menus.

Thanks for the information. Do you mean context-menu-mode? I'll keep an
eye on it. When you say terminal support, do you mean terminal emulators
or TTY? Because I often use Emacs on the linux framebuffer with fbterm,
and popup.el works fine on the tty. Also, I don't usually use the mouse
much (actually I only use it in Gimp and the like) and the combination
of popup.el with hyperbole is more comfortable and keyboard-centric for
me.


>> 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:
>
> May you explain more about how you attach to an email/upload?

Sure! But they are very simple functions, which I don't use much.
Although they work fine for what I want:

The first requires the imgur.el package; the second one needs gnus-dired-mode:

(defun my-org-link-to-ingur ()
    (interactive)
    (let* ((path (org-element-property :path (org-element-context))))
      (imgur-upload-image (expand-file-name path) nil t)))

  (defun my-org-link-to-mail-attachment ()
    (interactive)
    (let* ((path (org-element-property :path (org-element-context))))
      (gnus-dired-attach (list (expand-file-name path)))))

-- 
Juan Manuel Macías

https://juanmanuelmacias.com

https://lunotipia.juanmanuelmacias.com

https://gnutas.juanmanuelmacias.com


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Tip] Popup-menu with several actions for a link
  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
  0 siblings, 1 reply; 5+ messages in thread
From: Ihor Radchenko @ 2023-08-20  7:23 UTC (permalink / raw)
  To: Juan Manuel Macías; +Cc: orgmode

Juan Manuel Macías <maciaschain@posteo.net> writes:

>> Since Emacs 28, Emacs has built-in context menu. (terminal is also
>> supported) Moreover, major modes are encouraged to add support for
>> context menus.
>
> Thanks for the information. Do you mean context-menu-mode?

Yes.

> ... I'll keep an
> eye on it. When you say terminal support, do you mean terminal emulators
> or TTY?

Both.

> ... Also, I don't usually use the mouse
> much (actually I only use it in Gimp and the like) and the combination
> of popup.el with hyperbole is more comfortable and keyboard-centric for
> me.

By default, context menu is bound to S-<F10>. Who cares about mouse XD

>> May you explain more about how you attach to an email/upload?
>
> Sure! But they are very simple functions, which I don't use much.
> Although they work fine for what I want:
>
> The first requires the imgur.el package; the second one needs gnus-dired-mode:

I see. I thought that you are using built-in functionality.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Tip] Popup-menu with several actions for a link
  2023-08-20  7:23     ` Ihor Radchenko
@ 2023-08-20 10:13       ` Juan Manuel Macías
  0 siblings, 0 replies; 5+ messages in thread
From: Juan Manuel Macías @ 2023-08-20 10:13 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: orgmode

Ihor Radchenko writes:

>> ... Also, I don't usually use the mouse
>> much (actually I only use it in Gimp and the like) and the combination
>> of popup.el with hyperbole is more comfortable and keyboard-centric for
>> me.
>
> By default, context menu is bound to S-<F10>. Who cares about mouse XD

Oh I see. Very interesting. But I have seen that, at least by default,
there is no autocomplete feature. What I like about popup.el is, in
addition to autocompletion, the ability to easily create menus for
anything. Some time ago I defined a popup-menu[1] that shows me all the
header levels from where I am to the first one, defaulting to the
current level. It helps me situate myself in deep levels (other options
like imenu or org-sidebar give me too much information and I get lost).
I'm going to investigate if something similar can be done with
context-menu-mode...

Thank you for all the info!

[1] https://i.imgur.com/KoAZtIz.png
┌────
│ (defun my-org-where-i-am-popup ()
│   (interactive)
│   (setq org-heading-titles-list nil)
│   (org-with-wide-buffer
│    (save-excursion
│      (save-restriction
│        (org-back-to-heading t)
│        (if (eq (org-element-property :level (org-element-at-point)) 1)
│            (message "First level")
│          (push (cons (org-link-display-format
│                       (nth 4 (org-heading-components)))
│                      (point))
│                org-heading-titles-list)
│          (while
│              (ignore-errors (outline-up-heading 1 t))
│            (push (cons (org-link-display-format
│                         (nth 4 (org-heading-components)))
│                        (point))
│                  org-heading-titles-list))))))
│   (org-with-wide-buffer
│    (save-excursion
│      (save-restriction
│        (goto-char
│         (popup-menu* (mapcar
│                       (lambda (x)
│                         (popup-make-item (car x) :value (cdr x)))
│                       org-heading-titles-list)
│                      :isearch t
│                      :initial-index (length org-heading-titles-list)))
│        (org-tree-to-indirect-buffer)))))
└────

-- 
Juan Manuel Macías

https://juanmanuelmacias.com

https://lunotipia.juanmanuelmacias.com

https://gnutas.juanmanuelmacias.com


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-08-20 10:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-18 18:27 [Tip] Popup-menu with several actions for a link Juan Manuel Macías
2023-08-19 19:53 ` 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

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.