~ruther/nixos-config

ref: 82c41cc2f714c928b9651e785ea547432be313de nixos-config/home/modules/profiles/desktop/dwl/emacs-anywhere.el -rw-r--r-- 1.9 KiB
82c41cc2 — Frantisek Bohacek fix: add missing emacs-anywhere.el 8 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
(require 'server)

(server-eval-at "server" '(let
                              ((frame (make-frame-command))
                               (buffer (generate-new-buffer "*emacs-anywhere*")))

  (defun my-emacs-anywhere-capture ()
    "Open a buffer called *emacs-anywhere*, wait for user input, and return the buffer content when C-c C-c is pressed."
    (interactive)
    (let ((buffer-name "*emacs-anywhere*"))
      (with-current-buffer (get-buffer-create buffer-name)
        (erase-buffer)
        (local-set-key (kbd "C-c C-c") 'my-emacs-anywhere-finish-capture)
        (local-set-key (kbd "C-c C-k") 'my-emacs-anywhere-abort-capture)
        (message "Type your input. Press C-c C-c to finish.")
        (switch-to-buffer buffer-name))))


  (defvar my-emacs-anywhere-content nil
    "Variable to store the content captured from *emacs-anywhere* buffer.")

  (defun my-emacs-anywhere-finish-capture ()
    "Finish capturing input and return the content of the *emacs-anywhere* buffer."
    (interactive)
    (let ((content (buffer-string)))
      (setq my-emacs-anywhere-content content)
      (kill-buffer buffer)
      (delete-frame frame)))

  (defun my-emacs-anywhere-abort-capture ()
    "Finish capturing input and return the content of the *emacs-anywhere* buffer."
    (interactive)
    (setq my-emacs-anywhere-content t)
    (kill-buffer buffer)
    (delete-frame frame))

  (select-frame frame)
  (switch-to-buffer buffer)
  (erase-buffer)
  (my-emacs-anywhere-capture)
  (setq my-emacs-anywhere-content nil)
  t))

(while (let ((my-emacs-anywhere-content (server-eval-at "server" 'my-emacs-anywhere-content)))
         (or (not my-emacs-anywhere-content)
             (and
                  (with-temp-buffer
                    (insert my-emacs-anywhere-content)
                    (write-region (point-min) (point-max) "/dev/stdout"))
                   f)))
  (sit-for 0.1))
Do not follow this link