emacs-devel
[Top][All Lists]
Advanced

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

Re: NonGNU ELPA: New package 'xdg-appmenu'


From: Eshel Yaron
Subject: Re: NonGNU ELPA: New package 'xdg-appmenu'
Date: Sun, 09 Jul 2023 22:39:32 +0300
User-agent: Gnus/5.13 (Gnus v5.13)

Hey,

>> XDG Appmenu allows you to run XDG desktop application right from your
>> Emacs.  To run an application, just do `M-x xdg-appmenu'.

I've just tried it out and it seems convenient and works really well!

One suggestion: you could add an `annotation-function` in `xdg-appmenu`
instead of relying on integration with `marginalia`.  That way you can
get mostly the same results without requiring the user to install and
configure `marginalia`.  E.g.:

diff --git a/xdg-appmenu.el b/xdg-appmenu.el
index 733b5d7..a47dc99 100644
--- a/xdg-appmenu.el
+++ b/xdg-appmenu.el
@@ -29,13 +29,6 @@ ;;; Commentary:
 ;; XDG Appmenu allows you to run XDG desktop application right from
 ;; your Emacs.  To run an application, just do `M-x xdg-appmenu'.
 
-;; If you use Marginalia, you might want to add the following to your
-;; init file to show the description of each application in the
-;; minibuffer prompt:
-
-;;  (push '(xdg-app xdg-appmenu-marginalia-annotate builtin none)
-;;        marginalia-annotator-registry)
-
 ;;; Code:
 
 (require 'subr-x)
@@ -177,7 +170,8 @@ (defun xdg-appmenu (app)
             "Run application: "
             (lambda (string pred action)
               (if (eq action 'metadata)
-                  `(metadata (category . xdg-app))
+                  `(metadata (category . xdg-app)
+                             (annotation-function . xdg-appmenu-annotate))
                 (complete-with-action action xdg-appmenu--list
                                       string pred)))
             nil t nil 'xdg-appmenu-history))))
@@ -189,18 +183,18 @@ (defun xdg-appmenu (app)
       (when (nth 3 spec)
         (pop-to-buffer-same-window buffer)))))
 
-(defvar marginalia-separator)
-(declare-function marginalia--truncate "marginalia")
-
-(defun xdg-appmenu-marginalia-annotate (cand)
+(defun xdg-appmenu-annotate (cand)
   "Annotate candidate CAND with its comment."
-  (let ((spec (assoc cand xdg-appmenu--list)))
-    (if (or (not spec) (not (nth 4 spec))
-            (string-empty-p (nth 4 spec)))
-        ""
-      (concat #(" " 0 1 (marginalia--align t)) marginalia-separator
-              (propertize (marginalia--truncate (nth 4 spec) 1.0)
-                          'face 'marginalia-documentation)))))
+  (let* ((spec (assoc cand xdg-appmenu--list))
+         (max-width (seq-max (mapcar #'string-width
+                                     (mapcar #'car
+                                             xdg-appmenu--list))))
+         (annotation (nth 4 spec)))
+    (unless (or (not annotation) (string-empty-p annotation))
+      (concat
+       (propertize " " 'display
+                   `(space :align-to ,(+ 2 max-width)))
+       (truncate-string-to-width annotation 80 nil nil t)))))
 
 (defun xdg-appmenu-terminal-runner-term (app command)
   "Run shell command COMMAND in a Term buffer.



reply via email to

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