diff options
| -rwxr-xr-x | .stumpwm.d/init.lisp | 113 | 
1 files changed, 109 insertions, 4 deletions
| diff --git a/.stumpwm.d/init.lisp b/.stumpwm.d/init.lisp index bde84fd..2817839 100755 --- a/.stumpwm.d/init.lisp +++ b/.stumpwm.d/init.lisp | |||
| @@ -54,10 +54,6 @@ | |||
| 54 | ("C-g" . "ESC") | 54 | ("C-g" . "ESC") | 
| 55 | ("C-k" . ("C-S-End" "C-x"))))) | 55 | ("C-k" . ("C-S-End" "C-x"))))) | 
| 56 | 56 | ||
| 57 | (defcommand emacsclient () () | ||
| 58 | "Start emacs unless it is already running, in which case focus it." | ||
| 59 | (run-or-raise "emacsclient -c" '(:class "Emacs"))) | ||
| 60 | |||
| 61 | 57 | ||
| 62 | (run-shell-command "~/.fehbg") | 58 | (run-shell-command "~/.fehbg") | 
| 63 | 59 | ||
| @@ -241,3 +237,112 @@ | |||
| 241 | 237 | ||
| 242 | (define-key *misc-keymap* (kbd "h") "kto-hakuje-p") | 238 | (define-key *misc-keymap* (kbd "h") "kto-hakuje-p") | 
| 243 | (define-key *misc-keymap* (kbd "C-h") "kto-hakuje-p") | 239 | (define-key *misc-keymap* (kbd "C-h") "kto-hakuje-p") | 
| 240 | |||
| 241 | |||
| 242 | (defun emacs-server-p () | ||
| 243 | (let ((status-code (caddr | ||
| 244 | (multiple-value-list | ||
| 245 | (uiop:run-program "ls /run/user/$(id -u)/emacs/server" | ||
| 246 | :ignore-error-status T))))) | ||
| 247 | (= status-code 0))) | ||
| 248 | |||
| 249 | (stumpwm:defcommand emacs-start-server (&optional (show-message T) (wait-for-start NIL)) () | ||
| 250 | (let ((mess (if (not (emacs-server-p)) | ||
| 251 | (progn (stumpwm:run-shell-command "emacs --daemon" wait-for-start) | ||
| 252 | "Emacs server is starting....") | ||
| 253 | "Emacs server is running already!"))) | ||
| 254 | (when show-message (message mess)))) | ||
| 255 | |||
| 256 | (stumpwm:defcommand emacs-stop-server (&optional (show-message T)) () | ||
| 257 | (let ((mess (if (emacs-server-p) | ||
| 258 | (progn (stumpwm:run-shell-command "emacsclient -e \"(server-force-delete)\"") | ||
| 259 | "Emacs server gone away :(....") | ||
| 260 | "Emacs server wasn't alive!"))) | ||
| 261 | (when show-message (message mess)))) | ||
| 262 | |||
| 263 | |||
| 264 | (stumpwm:defcommand emacs-restart-server (&optional (show-message T)) () | ||
| 265 | (emacs-stop-server NIL) | ||
| 266 | (emacs-start-server show-message)) | ||
| 267 | |||
| 268 | (defun postwalk (fun tree) | ||
| 269 | (if (consp tree) | ||
| 270 | (loop :for a :in tree | ||
| 271 | :if (consp a) | ||
| 272 | :collect (postwalk fun a) | ||
| 273 | :else | ||
| 274 | :collect (funcall fun a)) | ||
| 275 | (funcall fun tree))) | ||
| 276 | |||
| 277 | (defmacro eval-emacs-sexp (sexp | ||
| 278 | &key (create-new-frame NIL)) | ||
| 279 | `(stumpwm:run-shell-command | ||
| 280 | (format nil "emacsclient~{ ~A~} '~A'" | ||
| 281 | (list ,(if create-new-frame "-c" "") | ||
| 282 | "-e") | ||
| 283 | (postwalk (lambda (x) | ||
| 284 | (cond | ||
| 285 | ((stringp x) (concat "\"" x "\"")) | ||
| 286 | ((symbolp x) (string-downcase (string x))) | ||
| 287 | (T x))) | ||
| 288 | ,sexp)) | ||
| 289 | ,(not create-new-frame))) | ||
| 290 | |||
| 291 | |||
| 292 | (defmacro defcommand-from-emacs (name | ||
| 293 | (&rest args) | ||
| 294 | (&rest interactive-args) | ||
| 295 | (&key (create-new-frame T) (output-wrapper NIL)) | ||
| 296 | &body body) | ||
| 297 | `(stumpwm:defcommand ,name ,args ,interactive-args | ||
| 298 | (when (not (emacs-server-p)) | ||
| 299 | (emacs-start-server NIL T)) | ||
| 300 | |||
| 301 | ,(let ((x `(eval-emacs-sexp (progn ,@body) | ||
| 302 | :create-new-frame ,create-new-frame))) | ||
| 303 | (cond | ||
| 304 | ((and create-new-frame output-wrapper) | ||
| 305 | (error "Cannot wrap the output, becaouse create-new-frame is T.")) | ||
| 306 | (output-wrapper `(funcall ,output-wrapper ,x)) | ||
| 307 | (T `(funcall (lambda (x) (progn x nil)) ,x)))))) | ||
| 308 | |||
| 309 | |||
| 310 | (defcommand-from-emacs emacs-client () () () | ||
| 311 | nil) | ||
| 312 | |||
| 313 | (defcommand-from-emacs emacs-calc () () () | ||
| 314 | '(full-calc)) | ||
| 315 | |||
| 316 | (defcommand-from-emacs emacs-org-agenda () () () | ||
| 317 | '(org-agenda-list)) | ||
| 318 | |||
| 319 | (defcommand-from-emacs emacs-mu4e () () () | ||
| 320 | '(mu4e)) | ||
| 321 | |||
| 322 | (defcommand-from-emacs emacs-shell () () () | ||
| 323 | '(shell)) | ||
| 324 | |||
| 325 | (defcommand-from-emacs emacs-eshell () () () | ||
| 326 | '(eshell)) | ||
| 327 | |||
| 328 | (defvar *emacs-keymap* | ||
| 329 | (let ((e (make-sparse-keymap))) | ||
| 330 | (define-key e (kbd "a") "emacs-org-agenda") | ||
| 331 | (define-key e (kbd "C-a") "emacs-org-agenda") | ||
| 332 | (define-key e (kbd "c") "emacs-calc") | ||
| 333 | (define-key e (kbd "C-c") "emacs-calc") | ||
| 334 | (define-key e (kbd "m") "emacs-mu4e") | ||
| 335 | (define-key e (kbd "C-m") "emacs-mu4e") | ||
| 336 | |||
| 337 | e)) | ||
| 338 | |||
| 339 | |||
| 340 | |||
| 341 | |||
| 342 | (define-key *root-map* (kbd "C-e") '*emacs-keymap*) | ||
| 343 | (define-key *root-map* (kbd "e") "emacs-client") | ||
| 344 | (define-key *root-map* (kbd "c") "emacs-shell") | ||
| 345 | (define-key *root-map* (kbd "C") "emacs-eshell") | ||
| 346 | |||
| 347 | |||
| 348 | (emacs-start-server nil) | ||
