emacs.lisp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. (in-package :stumpwm)
  2. (defun switch-to-emacs ()
  3. (unless (uiop/utility:string-prefix-p "Emacs"
  4. (window-class (current-window)))
  5. (run-shell-command "stumpish emacsclient")))
  6. (defmacro emacs-bind (key command)
  7. `(progn
  8. (defcommand ,(intern (concat "emacs-" command)) () ()
  9. (emacsclient-eval (format nil "(~a)" ,command)))
  10. (define-key *top-map* (kbd ,key) ,(concat "emacs-" command))))
  11. (defun emacsclient-command (&rest args)
  12. (run-shell-command (format nil "emacsclient ~a" (join args))))
  13. (defun emacsclient-eval (command)
  14. (emacsclient-command (format nil "-e ~s" command)))
  15. (defun emacs-eval (command)
  16. (run-shell-command
  17. (format nil "emacs --eval ~s"
  18. (sb-unicode:lowercase (write-to-string command)))))
  19. (defun emacs-buffer (buffer)
  20. (emacsclient-command "-s" "chat"
  21. (format nil "-e ~s"
  22. (format nil "(switch-to-buffer ~s)" buffer))
  23. "-c"))
  24. (defun emacs-erc ()
  25. (mapcar #'(lambda (buffer)
  26. (emacs-buffer buffer))
  27. '("#bash" "#bootstrappable" "##C" "#chicken" "#emacs" "#erc" "#fsf"
  28. "#gdb" "#gnus" "#guile" "#guix" "##linux" "#lisp" "#nixos"
  29. "#scheme" "#stumpwm")))
  30. (defcommand emacsclient () ()
  31. "Start emacs unless it is already running, in which case focus it."
  32. (if (uiop:file-exists-p "/run/user/1000/emacs/server")
  33. (run-or-raise "emacsclient -c" '(:class "Emacs"))
  34. (sb-thread:make-thread
  35. (lambda ()
  36. (run-shell-command "emacs --daemon")
  37. (message "Running Emacs daemon.")
  38. (loop while (not (uiop:file-exists-p "/run/user/1000/emacs/server"))
  39. do (sleep 3))
  40. (run-or-raise "emacsclient -c" '(:class "Emacs"))))))
  41. (defcommand emacsclient-new () ()
  42. (run-shell-command "emacsclient -c"))
  43. (defcommand xclip-emacs () ()
  44. "Open file from clipboard."
  45. (run-shell-command
  46. (join (list "exec emacsclient -c" (get-x-selection)))))
  47. (defcommand emacs-vterm () ()
  48. ""
  49. (switch-to-emacs)
  50. (run-shell-command "emacsclient -e '(progn (vterm-toggle))'"))
  51. (defcommand emacs-shell () ()
  52. ""
  53. (switch-to-emacs)
  54. (run-shell-command "emacsclient -e '(progn (shell) (delete-other-windows))'"))
  55. (defcommand helm-tramp () ()
  56. (progn (run-shell-command "emacsclient --eval '(helm-tramp)'")
  57. (switch-to-emacs)))
  58. (defcommand emacs-counsel-find-file () ()
  59. (progn (run-shell-command "emacsclient --eval '(counsel-find-file)'")))
  60. (defcommand emacs-counsel-M-x () ()
  61. (progn (run-shell-command "emacsclient --eval '(counsel-M-x)'")))
  62. (defcommand emacs-anywhere () ()
  63. "Run `emacs-anywhere'."
  64. (run-shell-command "emacs-anywhere"))
  65. ;;;
  66. ;;; Project
  67. ;;;
  68. (defcommand wi-project-ivy () ()
  69. (progn (run-shell-command "emacsclient --eval '(wi-project-ivy)'")
  70. (switch-to-emacs)))
  71. (defcommand wi-project-browse-at-remote () ()
  72. (progn (run-shell-command "emacsclient --eval '(wi-project-browse-at-remote)'")
  73. (switch-to-emacs)))
  74. ;;;
  75. ;;; EMMS
  76. ;;;
  77. (defcommand emacs-mms-next () ()
  78. (emacsclient-eval (format nil "(~a)" "emms-next")))
  79. (defcommand emacs-emms-previous () ()
  80. (emacsclient-eval (format nil "(~a)" "emms-previous")))
  81. (defcommand emacs-emms-pause () ()
  82. (emacsclient-eval (format nil "(~a)" "emms-pause")))
  83. (defcommand emacs-emms-random () ()
  84. (emacsclient-eval (format nil "(~a)" "emms-random")))
  85. (defcommand emms () ()
  86. (switch-to-emacs)
  87. (run-shell-command
  88. (format nil "emacsclient -e ~s"
  89. (sb-unicode:lowercase
  90. (write-to-string
  91. '(progn (emms) (delete-other-windows)))))))
  92. ;;;
  93. ;;; org-mode
  94. ;;;
  95. (defcommand emacs-org-capture () ()
  96. "Capture URL with Emacs Org from GUI clipboard"
  97. (run-shell-command
  98. (join (list "exec"
  99. (concat (getenv "HOME") "/bin/emacs-org-capture")
  100. (get-x-selection)))))
  101. (defcommand org () ()
  102. (progn (run-shell-command "emacsclient --eval '(plain-org-wiki)'")
  103. (switch-to-emacs)))
  104. (defcommand org-agenda () ()
  105. (progn (run-shell-command "emacsclient --eval '(org-agenda)'")
  106. (switch-to-emacs)))
  107. (defcommand emacs-todo () ()
  108. (progn (run-shell-command (format nil "emacsclient --eval '(find-file ~s)'" "~/src/gitlab.com/wigust/notes/todo.org"))
  109. (switch-to-emacs)))
  110. (defcommand emacs-todo-new-window () ()
  111. (run-shell-command (format nil "emacsclient -cn --eval '(find-file ~s)'" "~/src/gitlab.com/wigust/notes/todo.org")))
  112. ;;;
  113. ;;; Mail
  114. ;;;
  115. (defcommand gnus () ()
  116. (run-shell-command "emacsclient --eval '(gnus)'")
  117. (switch-to-emacs))
  118. (defcommand gnus-new-window () ()
  119. (run-shell-command (format nil "emacsclient -c -e ~s"
  120. (sb-unicode:lowercase (write-to-string '(gnus))))))
  121. ;;;
  122. ;;; Guix
  123. ;;;
  124. (defcommand guix () ()
  125. (switch-to-emacs)
  126. (run-shell-command "magit /home/oleg/src/git.savannah.gnu.org/git/guix"))
  127. (defcommand guix-wigust () ()
  128. (progn (run-shell-command "emacsclient --eval '(let ((default-directory (expand-file-name \"/home/oleg/src/cgit.duckdns.org/git/guix/guix-wigust/guix/wigust/packages/\"))) (counsel-find-file))'")
  129. (switch-to-emacs)))
  130. (defcommand emacs-guix-edit () ()
  131. (let ((clipboard (get-x-selection)))
  132. (message (format nil "Guix edit ~a" clipboard))
  133. (switch-to-emacs)
  134. (run-shell-command (format nil "emacsclient -e '(guix-edit ~s)'" clipboard))))
  135. ;;;
  136. ;;; RSS
  137. ;;;
  138. (defcommand elfeed () ()
  139. (switch-to-emacs)
  140. (run-shell-command
  141. (format nil "emacsclient -e ~s"
  142. (sb-unicode:lowercase
  143. (write-to-string
  144. '(progn (elfeed) (delete-other-windows)))))))
  145. (defcommand elfeed-new-window () ()
  146. (run-shell-command
  147. (format nil "emacsclient -c -e ~s" (sb-unicode:lowercase (write-to-string '(elfeed))))))