Nicolas Graves: 4 rde: Add emacs-dmenu command. rde: Add emacs-dmenu command. rde: Add emacs-dmenu command. rde: Add emacs-dmenu command. 4 files changed, 147 insertions(+), 8 deletions(-)
On 2023-08-06 10:55, Nicolas Graves wrote: Hi Nicolas!
I tried ls | $MENU and got: --8<---------------cut here---------------start------------->8--- /gnu/store/rib9g2ig1xf3kclyl076w28parmncg4k-bash-minimal-5.1.16/bin/bash: -c: line 1: unexpected EOF while looking for matching ``' /gnu/store/rib9g2ig1xf3kclyl076w28parmncg4k-bash-minimal-5.1.16/bin/bash: -c: line 21: syntax error: unexpected end of file Backtrace: 3 (primitive-load "/gnu/store/z4gfi5ky1gg8jyhggaxr5ghj81v…") In ice-9/eval.scm: 293:34 2 (_ #(#(#<directory (guile-user) 7f6f96518c80> "CHA…") #)) 159:9 1 (_ #(#(#<directory (guile-user) 7f6f96518c80> "CHA…") #)) In unknown file: 0 (string-drop-right "" 2) ERROR: In procedure string-drop-right: Value out of range 0 to< 0: -2 zsh: done ls | zsh: exit 1 $MENU/gnu/store/rib9g2ig1xf3kclyl076w28parmncg4k-bash-minimal-5.1.16/bin/bash: -c: line 1: unexpected EOF while looking for matching ``' /gnu/store/rib9g2ig1xf3kclyl076w28parmncg4k-bash-minimal-5.1.16/bin/bash: -c: line 21: syntax error: unexpected end of file Backtrace: 3 (primitive-load "/gnu/store/z4gfi5ky1gg8jyhggaxr5ghj81v…") In ice-9/eval.scm: 293:34 2 (_ #(#(#<directory (guile-user) 7f6f96518c80> "CHA…") #)) 159:9 1 (_ #(#(#<directory (guile-user) 7f6f96518c80> "CHA…") #)) In unknown file: 0 (string-drop-right "" 2) ERROR: In procedure string-drop-right: Value out of range 0 to< 0: -2 zsh: done ls | zsh: exit 1 $MENU --8<---------------cut here---------------end--------------->8---
Looks much better, applied, lightly tested, pushed. Thank you for your work! :)
Copy & paste the following snippet into your terminal to import this patchset into git:
curl -s https://lists.sr.ht/~abcdw/rde-devel/patches/39843/mbox | git am -3Learn more about email & git
--- src/rde/features/emacs.scm | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/rde/features/emacs.scm b/src/rde/features/emacs.scm index baa01ca..88465e0 100644 --- a/src/rde/features/emacs.scm +++ b/src/rde/features/emacs.scm @@ -327,6 +327,37 @@ environment outside of Guix Home." "--no-splash" (cdr (command-line))))) + ;; Emacs and emacsclient don't handle stdin properly, in the case they + ;; should be used as dmenu. This tiny guile+emacs script behaves like dmenu. + (define emacs-dmenu + (program-file + "emacs-dmenu" + #~(begin + (use-modules + (ice-9 textual-ports) + (ice-9 popen)) + (let* ((raw-input + (string-drop-right (get-string-all (current-input-port)) 1)) + (port (open-input-pipe + (string-append + #$emacs-client-create-frame + " --eval \"" + "(progn \ +(set-frame-name \\\"dynamic-menu - Emacs Client\\\") \ +(let ((vertico-count 10)) \ + (completing-read \\\"Select: \\\" \ + (split-string \\\"" raw-input "\\\" \ + \\\"\n\\\"))))\"" + " --eval \"(delete-frame (selected-frame))\"" + " -F " + "\"((minibuffer . only) \ + (width . 120) \ + (height . 11))\""))) + (selected + (string-drop (string-drop-right (get-string-all port) 2) 1))) + (close-port port) + (format #t "~a\n" selected))))) + (define emacs-application-launcher (emacs-minibuffer-program emacs-client-create-frame "application-launcher" "Application Launcher" @@ -573,7 +604,8 @@ It can contain settings not yet moved to separate features." (simple-service 'emacs-set-default-editor home-environment-variables-service-type `(("ALTERNATE_EDITOR" . ,emacs-editor) - ("VISUAL" . ,emacs-client-no-wait))) + ("VISUAL" . ,emacs-client-no-wait) + ("MENU" . ,emacs-dmenu))) (when (get-value 'sway config) (simple-service 'emacs-update-environment-variables-on-sway-start @@ -594,7 +626,7 @@ It can contain settings not yet moved to separate features." (make-feature-values standalone-minibuffer-height emacs - emacs-editor emacs-client + emacs-editor emacs-client emacs-dmenu emacs-client-create-frame emacs-client-no-wait emacs-configure-rde-keymaps -- 2.39.2
--- src/rde/features/emacs.scm | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/rde/features/emacs.scm b/src/rde/features/emacs.scm index b893fb51..98bd132b 100644 --- a/src/rde/features/emacs.scm +++ b/src/rde/features/emacs.scm @@ -482,6 +482,37 @@ It can contain settings not yet moved to separate features." "--no-splash" (cdr (command-line))))) + ;; Emacs and emacsclient don't handle stdin properly, in the case they + ;; should be used as dmenu. This tiny guile+emacs script behaves like dmenu. + (define emacs-dmenu + (program-file + "emacs-dmenu" + #~(begin + (use-modules + (ice-9 textual-ports) + (ice-9 popen)) + (let* ((raw-input + (string-drop-right (get-string-all (current-input-port)) 1)) + (port (open-input-pipe + (string-append + #$emacs-client-create-frame + " --eval \"" + "(progn \ +(set-frame-name \\\"dynamic-menu - Emacs Client\\\") \ +(let ((vertico-count 10)) \ + (completing-read \\\"Select: \\\" \ + (split-string \\\"" raw-input "\\\" \ + \\\"\n\\\"))))\"" + " --eval \"(delete-frame (selected-frame))\"" + " -F " + "\"((minibuffer . only) \ + (width . 120) \ + (height . 11))\""))) + (selected + (string-drop (string-drop-right (get-string-all port) 2) 1))) + (close-port port) + (format #t "~a\n" selected))))) + (define emacs-application-launcher (emacs-minibuffer-program emacs-client-create-frame "application-launcher" "Application Launcher" @@ -536,7 +567,8 @@ It can contain settings not yet moved to separate features." (simple-service 'emacs-set-default-editor home-environment-variables-service-type `(("ALTERNATE_EDITOR" . ,emacs-editor) - ("VISUAL" . ,emacs-client-no-wait))) + ("VISUAL" . ,emacs-client-no-wait) + ("MENU" . ,emacs-dmenu))) (when (get-value 'sway config) (simple-service 'emacs-update-environment-variables-on-sway-start @@ -557,7 +589,7 @@ It can contain settings not yet moved to separate features." (make-feature-values standalone-minibuffer-height emacs - emacs-editor emacs-client + emacs-editor emacs-client emacs-dmenu emacs-client-create-frame emacs-client-no-wait emacs-configure-rde-keymaps -- 2.41.0
--- src/rde/features/emacs.scm | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/src/rde/features/emacs.scm b/src/rde/features/emacs.scm index b5cfe30e..95280370 100644 --- a/src/rde/features/emacs.scm +++ b/src/rde/features/emacs.scm @@ -481,6 +481,38 @@ It can contain settings not yet moved to separate features." "--no-splash" (cdr (command-line))))) + ;; Emacs and emacsclient don't handle stdin properly, in the case they + ;; should be used as dmenu. This tiny guile+emacs script behaves like dmenu. + (define emacs-dmenu + (program-file + "emacs-dmenu" + #~(begin + (use-modules + (ice-9 textual-ports) + (ice-9 popen)) + (let* ((raw-input + (string-drop-right (get-string-all (current-input-port)) 1))
It's not clear what does this string-drop-right do.
+ (port (open-input-pipe + (format #f + "~a --eval \" \ +(let* ((vertico-count 10) \ + (after-make-frame-functions '()) \ + (minibuffer-frame (make-frame `((display . ,(getenv \"WAYLAND_DISPLAY\")) \ + (name . \"dynamic menu - Emacs Client\") \ + (minibuffer . only) \ + (width . 120) \ + (height . 11))))) \ + (unwind-protect \ + (with-selected-frame minibuffer-frame \ + (completing-read \\\"Select: \\\" \ + (split-string \\\"~a\\\" \\\"\n\\\"))) \ + (delete-frame minibuffer-frame)))\"" + #$emacs-client raw-input))) + (selected + (string-drop (string-drop-right (get-string-all port) 2) 1)))
The same here.
+ (close-port port) + (format #t "~a\n" selected))))) + (define emacs-application-launcher (emacs-minibuffer-program emacs-client-create-frame "application-launcher" "Application Launcher" @@ -535,7 +567,8 @@ It can contain settings not yet moved to separate features." (simple-service 'emacs-set-default-editor home-environment-variables-service-type `(("ALTERNATE_EDITOR" . ,emacs-editor) - ("VISUAL" . ,emacs-client-no-wait))) + ("VISUAL" . ,emacs-client-no-wait) + ("MENU" . ,emacs-dmenu))) (when (get-value 'sway config) (simple-service 'emacs-update-environment-variables-on-sway-start @@ -556,7 +589,7 @@ It can contain settings not yet moved to separate features." (make-feature-values standalone-minibuffer-height emacs - emacs-editor emacs-client + emacs-editor emacs-client emacs-dmenu emacs-client-create-frame emacs-client-no-wait emacs-configure-rde-keymaps -- 2.41.0
On 2023-08-06 10:55, Nicolas Graves wrote: Hi Nicolas!
I tried ls | $MENU and got: --8<---------------cut here---------------start------------->8--- /gnu/store/rib9g2ig1xf3kclyl076w28parmncg4k-bash-minimal-5.1.16/bin/bash: -c: line 1: unexpected EOF while looking for matching ``' /gnu/store/rib9g2ig1xf3kclyl076w28parmncg4k-bash-minimal-5.1.16/bin/bash: -c: line 21: syntax error: unexpected end of file Backtrace: 3 (primitive-load "/gnu/store/z4gfi5ky1gg8jyhggaxr5ghj81v…") In ice-9/eval.scm: 293:34 2 (_ #(#(#<directory (guile-user) 7f6f96518c80> "CHA…") #)) 159:9 1 (_ #(#(#<directory (guile-user) 7f6f96518c80> "CHA…") #)) In unknown file: 0 (string-drop-right "" 2) ERROR: In procedure string-drop-right: Value out of range 0 to< 0: -2 zsh: done ls | zsh: exit 1 $MENU/gnu/store/rib9g2ig1xf3kclyl076w28parmncg4k-bash-minimal-5.1.16/bin/bash: -c: line 1: unexpected EOF while looking for matching ``' /gnu/store/rib9g2ig1xf3kclyl076w28parmncg4k-bash-minimal-5.1.16/bin/bash: -c: line 21: syntax error: unexpected end of file Backtrace: 3 (primitive-load "/gnu/store/z4gfi5ky1gg8jyhggaxr5ghj81v…") In ice-9/eval.scm: 293:34 2 (_ #(#(#<directory (guile-user) 7f6f96518c80> "CHA…") #)) 159:9 1 (_ #(#(#<directory (guile-user) 7f6f96518c80> "CHA…") #)) In unknown file: 0 (string-drop-right "" 2) ERROR: In procedure string-drop-right: Value out of range 0 to< 0: -2 zsh: done ls | zsh: exit 1 $MENU --8<---------------cut here---------------end--------------->8---
--- src/rde/features/emacs.scm | 46 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/src/rde/features/emacs.scm b/src/rde/features/emacs.scm index 25d34514..01cb8837 100644 --- a/src/rde/features/emacs.scm +++ b/src/rde/features/emacs.scm @@ -477,6 +477,47 @@ It can contain settings not yet moved to separate features." "--no-splash" (cdr (command-line))))) + ;; Emacs and emacsclient don't handle stdin properly, in the case they + ;; should be used as dmenu. This tiny guile+emacs script behaves like dmenu. + (define emacs-dmenu + (program-file + "emacs-dmenu" + #~(begin + (use-modules (ice-9 textual-ports) (ice-9 popen)) + (let* ((raw-input (get-string-all (current-input-port))) + (len (string-length raw-input)) + (clean-input + (if (and (> len 0) + (char=? (string-ref raw-input (- len 1)) #\newline)) + (string-drop-right raw-input 1) + raw-input)) + (count (string-count clean-input #\newline)) + (port (open-input-pipe + (format #f "~a --eval \"\ +(let* ((vertico-count ~a)\ + (after-make-frame-functions '())\ + (minibuffer-frame\ + (make-frame (list (cons 'display (getenv \\\"WAYLAND_DISPLAY\\\"))\
This line can make a script "wayland"-dependend without making sure that we are in wayland. Added a comment about it.
+ '(name . \\\"dynamic menu - Emacs Client\\\")\ + '(minibuffer . only)\ + '(width . 120)\ + '(height . ~a)))))\ + (unwind-protect\ + (with-selected-frame minibuffer-frame\ + (completing-read \\\"Select: \\\"\ + (split-string \\\"~a\\\" \\\"\n\\\")))\ + (delete-frame minibuffer-frame)))\"" + #$emacs-client + (+ 1 count) + (+ 2 count) + clean-input))) + ;; Drop surrounding quotes and newline. + (selected (string-drop + (string-drop-right (get-string-all port) 2) + 1))) + (close-port port) + (format #t "~a\n" selected))))) + (define emacs-application-launcher (emacs-minibuffer-program emacs-client "application-launcher" "Application Launcher" @@ -527,7 +568,8 @@ It can contain settings not yet moved to separate features." (simple-service 'emacs-set-default-editor home-environment-variables-service-type `(("ALTERNATE_EDITOR" . ,emacs-editor) - ("VISUAL" . ,emacs-client-no-wait))) + ("VISUAL" . ,emacs-client-no-wait) + ("MENU" . ,emacs-dmenu))) (when (get-value 'sway config) (simple-service 'emacs-update-environment-variables-on-sway-start @@ -544,7 +586,7 @@ It can contain settings not yet moved to separate features." (make-feature-values standalone-minibuffer-height emacs - emacs-editor emacs-client + emacs-editor emacs-client emacs-dmenu emacs-client-create-frame emacs-client-no-wait emacs-configure-rde-keymaps -- 2.41.0
Looks much better, applied, lightly tested, pushed. Thank you for your work! :)