2023-09-16 19:54:12 +02:00
|
|
|
:PROPERTIES:
|
|
|
|
:header-args:emacs-lisp: :comments link :results none
|
|
|
|
:ID: 0d92c672-5ac7-44dc-b021-cc58544f8eea
|
|
|
|
:END:
|
|
|
|
#+title: Emacs Rofi
|
|
|
|
#+filetags: emacs-load
|
|
|
|
It is possible to make a fake rofi, from emacs ~completing-read~. This file facilitates that. First we define some LISP functions.
|
|
|
|
|
|
|
|
#+begin_src emacs-lisp
|
2023-09-16 19:34:05 +02:00
|
|
|
(defun completing-read-frame-popup-file (prompt file display width height &rest args)
|
2023-09-16 19:54:12 +02:00
|
|
|
""
|
|
|
|
(with-temp-buffer
|
|
|
|
(insert-file-contents file)
|
2023-09-16 19:34:05 +02:00
|
|
|
(apply #'auxmenu-popup-frame prompt (string-lines (substring-no-properties (buffer-string))) display width height args)))
|
2023-09-16 19:54:12 +02:00
|
|
|
#+end_src
|
|
|
|
|
|
|
|
#+begin_src emacs-lisp
|
2023-09-16 19:34:05 +02:00
|
|
|
(defvar auxmenu-frame-alist nil)
|
2023-09-16 19:54:12 +02:00
|
|
|
|
2023-09-16 19:34:05 +02:00
|
|
|
(defun auxmenu-popup-frame (prompt collection display width height &rest args)
|
|
|
|
""
|
|
|
|
(let ((frame (alist-get display auxmenu-frame-alist)))
|
|
|
|
(when (equal frame nil)
|
|
|
|
(when (equal display nil)
|
|
|
|
(error "Must specify display"))
|
|
|
|
|
|
|
|
(push `(,display . ,(make-frame
|
|
|
|
`((minibuffer . only)
|
|
|
|
(name . "emacs-completing-read-float")
|
|
|
|
(unsplittable . t)
|
|
|
|
(no-other-frame . t)
|
|
|
|
(width . ,width)
|
|
|
|
(height . ,height)
|
|
|
|
(display . ,display)
|
|
|
|
(left . 0.5)
|
|
|
|
(top . 0.5))))
|
|
|
|
auxmenu-frame-alist)
|
|
|
|
(setq frame (alist-get display auxmenu-frame-alist)))
|
|
|
|
(make-frame-visible frame)
|
|
|
|
(raise-frame frame)
|
|
|
|
(with-selected-frame frame
|
2023-09-16 19:54:12 +02:00
|
|
|
(unwind-protect
|
|
|
|
(let ((selection (apply #'completing-read prompt collection args)))
|
2023-09-16 19:34:05 +02:00
|
|
|
(make-frame-invisible frame)
|
2023-09-16 19:54:12 +02:00
|
|
|
selection)
|
2023-09-16 19:34:05 +02:00
|
|
|
(make-frame-invisible frame)))))
|
2023-09-16 19:54:12 +02:00
|
|
|
#+end_src
|
|
|
|
|
|
|
|
Next a bash helper is needed.
|
|
|
|
|
|
|
|
#+begin_src shell
|
|
|
|
function emacs-rofi()
|
|
|
|
{
|
|
|
|
tmp=$(mktemp)
|
|
|
|
tee > $tmp
|
2023-09-16 19:34:05 +02:00
|
|
|
emacs -Q --batch --eval $"(progn (require 'server) (princ (format \"%s\\n\" (server-eval-at \"server\" '(completing-read-frame-popup-file \"$1\" \"$tmp\" \"$DISPLAY\" $2 $3)))))"
|
2023-09-16 19:54:12 +02:00
|
|
|
rm $tmp
|
|
|
|
}
|
|
|
|
#+end_src
|
|
|
|
|
|
|
|
Which then ought to be used like so.
|
|
|
|
|
|
|
|
#+begin_src shell
|
|
|
|
echo -e "test1\ntest2\ntest3" | emacs-rofi "test"
|
|
|
|
#+end_src
|
|
|
|
|