changelog shortlog graph tags branches files raw help

Mercurial > infra > home / changeset: stumpwm utils

changeset 86: a86cb552d6df
parent 85: 862659891933
child 93: 0e41a0a68353
author: Richard Westhaver <ellis@rwest.io>
date: Wed, 21 Aug 2024 20:29:13 -0400
files: .emacs.d/ellis.el .emacs.d/lib/stumpwm-mode.el .emacs.d/lib/stumpwm-utils.el .stumpwm.d/init.lisp
description: stumpwm utils
     1.1--- a/.emacs.d/ellis.el	Thu Aug 15 21:53:06 2024 -0400
     1.2+++ b/.emacs.d/ellis.el	Wed Aug 21 20:29:13 2024 -0400
     1.3@@ -1,4 +1,4 @@
     1.4-;;; ellis.el --- Richard's custom Emacs config -*- lexical-binding: t -*-
     1.5+;;; ellis.el --- user Emacs config -*- lexical-binding: t -*-
     1.6 
     1.7 ;; Copyright (C) 2024
     1.8 
     1.9@@ -81,12 +81,15 @@
    1.10 (keymap-set minibuffer-local-map "C-<tab>" #'hippie-expand)
    1.11 (keymap-set ctl-x-x-map "p p" #'remember-project)
    1.12 (keymap-set ctl-x-x-map "p l" #'remember-lab-projects)
    1.13+(keymap-set ctl-x-x-map "p c" #'remember-comp-projects)
    1.14 
    1.15 (add-hook 'prog-mode-hook #'skel-minor-mode)
    1.16 (add-hook 'org-mode-hook #'skel-minor-mode)
    1.17 ;; (add-hook 'prog-mode-hook #'company-mode)
    1.18 
    1.19 (add-hook 'notmuch-message-mode-hook #'turn-on-orgtbl)
    1.20+(
    1.21+ouse-package ef-themes :ensure t)
    1.22 
    1.23 (use-package markdown-mode :ensure t)
    1.24 
    1.25@@ -742,18 +745,11 @@
    1.26   (auto-insert-mode t)
    1.27   (keymap-set skel-minor-mode-map "C-<return>" 'company-tempo))
    1.28 
    1.29-;;; dictionary
    1.30-;; requires dictd server running
    1.31-(setq dictionary-server "compiler.company")
    1.32-;;; ispell
    1.33-;; requires aspell and a hunspell dictionary (hunspell-en_us)
    1.34-(setq-default ispell-program-name "aspell")
    1.35-(add-hook 'mail-send-hook  #'ispell-message)
    1.36 ;;; glossary
    1.37-(with-eval-after-load 'org-glossary
    1.38-  (setq org-glossary-collection-root (join-paths company-source-directory "org/meta/"))
    1.39-  (cl-pushnew '("Terms" . glossary) org-glossary-headings)
    1.40-  (cl-pushnew '("Acronyms" . acronym) org-glossary-headings))
    1.41+;; (with-eval-after-load 'org-glossary
    1.42+;;   (setq org-glossary-collection-root (join-paths company-source-directory "org/meta/"))
    1.43+;;   (cl-pushnew '("Terms" . glossary) org-glossary-headings)
    1.44+;;   (cl-pushnew '("Acronyms" . acronym) org-glossary-headings))
    1.45 
    1.46 (provide 'ellis)
    1.47-;;; ellis.el ends here
    1.48+;; ellis.el ends here
     2.1--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2+++ b/.emacs.d/lib/stumpwm-mode.el	Wed Aug 21 20:29:13 2024 -0400
     2.3@@ -0,0 +1,68 @@
     2.4+;;; stumpwm-mode.el --- special lisp mode for evaluating code into running stumpwm
     2.5+
     2.6+;; Copyright (C) 2007  Shawn Betts
     2.7+
     2.8+;; Maintainer: Shawn Betts
     2.9+;; Keywords: comm, lisp, tools
    2.10+
    2.11+;; This file is free software; you can redistribute it and/or modify
    2.12+;; it under the terms of the GNU General Public License as published by
    2.13+;; the Free Software Foundation; either version 2, or (at your option)
    2.14+;; any later version.
    2.15+
    2.16+;; This file is distributed in the hope that it will be useful,
    2.17+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.18+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    2.19+;; GNU General Public License for more details.
    2.20+
    2.21+;; You should have received a copy of the GNU General Public License
    2.22+;; along with GNU Emacs; see the file COPYING.  If not, see
    2.23+;; <http://www.gnu.org/licenses/>.
    2.24+
    2.25+;;; Commentary:
    2.26+
    2.27+;; load this file, set stumpwm-shell-program to point to stumpish and
    2.28+;; run M-x stumpwm-mode in your stumpwm lisp files. Now, you can
    2.29+;; easily eval code into a running stumpwm using the regular bindings.
    2.30+
    2.31+;;; Code:
    2.32+
    2.33+(defvar stumpwm-shell-program "stumpish"
    2.34+  "program name, including path if needed, for the stumpish program.")
    2.35+
    2.36+;;;###autoload 
    2.37+(define-minor-mode stumpwm-mode
    2.38+    "add some bindings to eval code into a running stumpwm using stumpish."
    2.39+  :global nil
    2.40+  :lighter " StumpWM"
    2.41+  :keymap (let ((m (make-sparse-keymap)))
    2.42+            (define-key m (kbd "C-M-x") 'stumpwm-eval-defun)
    2.43+            (define-key m (kbd "C-x C-e") 'stumpwm-eval-last-sexp)
    2.44+            m))
    2.45+
    2.46+(defun stumpwm-eval-region (start end)
    2.47+  (interactive "r")
    2.48+  (let ((s (buffer-substring-no-properties start end)))
    2.49+    (message "%s"
    2.50+             (with-temp-buffer
    2.51+               (call-process stumpwm-shell-program nil (current-buffer) nil
    2.52+                             "eval"
    2.53+                             s)
    2.54+               (delete-char -1)
    2.55+               (buffer-string)))))
    2.56+
    2.57+(defun stumpwm-eval-defun ()
    2.58+  (interactive)
    2.59+  (save-excursion
    2.60+    (end-of-defun)
    2.61+    (skip-chars-backward " \t\n\r\f")
    2.62+    (let ((end (point)))
    2.63+      (beginning-of-defun)
    2.64+      (stumpwm-eval-region (point) end))))
    2.65+
    2.66+(defun stumpwm-eval-last-sexp ()
    2.67+  (interactive)
    2.68+  (stumpwm-eval-region (save-excursion (backward-sexp) (point)) (point)))
    2.69+
    2.70+(provide 'stumpwm-mode)
    2.71+;;; stumpwm-mode.el ends here
     3.1--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2+++ b/.emacs.d/lib/stumpwm-utils.el	Wed Aug 21 20:29:13 2024 -0400
     3.3@@ -0,0 +1,79 @@
     3.4+(defun stumpwm-connect ()
     3.5+  "Start slime and connect to the lisp image that is running the
     3.6+  swank server.  Must have \"(require 'swank) 
     3.7+  (swank:create-server)\" in your .stumpwmrc "
     3.8+  (interactive)
     3.9+  (slime-connect "127.0.0.1"  4005)
    3.10+  (with-current-buffer (current-buffer)
    3.11+    (rename-buffer "*sbcl-stumpwm-repl*")
    3.12+    (slime-eval '(in-package :stumpwm))))
    3.13+
    3.14+(defun stumpwm-disconnect ()
    3.15+  "Disconnects from the swank server currently open."
    3.16+  (with-current-buffer 
    3.17+      (switch-to-buffer "*sbcl-stumpwm-repl*")
    3.18+    (slime-disconnect)))
    3.19+;;Lifted (with stylistic changes) from http://www.emacswiki.org/emacs/EmacsAsDaemon#toc9
    3.20+(defun modified-buffers-exist () 
    3.21+  "This function will check to see if there are any buffers
    3.22+that have been modified.  It will return true if there are
    3.23+and nil otherwise. Buffers that have buffer-offer-save set to
    3.24+nil are ignored."
    3.25+  (let (modified-found)
    3.26+    (dolist (buffer (buffer-list))
    3.27+      (when (and (buffer-live-p buffer)
    3.28+		 (buffer-modified-p buffer)
    3.29+		 (not (buffer-base-buffer buffer))
    3.30+		 (or
    3.31+		  (buffer-file-name buffer)
    3.32+		  (progn
    3.33+		    (set-buffer buffer)
    3.34+		    (and buffer-offer-save (> (buffer-size) 0)))))
    3.35+	(setq modified-found t)))
    3.36+    modified-found))
    3.37+
    3.38+(defun stumpwm-daemon-shutdown-emacs (&optional display)
    3.39+  " This is a function that can bu used to shutdown save buffers and 
    3.40+shutdown the emacs daemon. It should be called using 
    3.41+emacsclient -e '(stumpwm-daemon-shutdown-emacs)'.  This function will
    3.42+check to see if there are any modified buffers or active clients
    3.43+or frame.  If so an x window will be opened and the user will
    3.44+be prompted."
    3.45+
    3.46+  (let (new-frame modified-buffers active-clients-or-frames)
    3.47+    ; Check if there are modified buffers or active clients or frames.
    3.48+    (setq modified-buffers (modified-buffers-exist))
    3.49+    (setq active-clients-or-frames ( or (> (length server-clients) 1)
    3.50+					(> (length (frame-list)) 1)))  
    3.51+    ; Create a new frame if prompts are needed.
    3.52+    (when (or modified-buffers active-clients-or-frames)
    3.53+      (when (not (eq window-system 'x))
    3.54+	(message "Initializing x windows system.")
    3.55+	(x-initialize-window-system))
    3.56+      (when (not display) (setq display (getenv "DISPLAY")))
    3.57+      (message "Opening frame on display: %s" display)
    3.58+      (select-frame (make-frame-on-display display '((window-system . x)))))
    3.59+    ; Save the current frame.  
    3.60+    (setq new-frame (selected-frame))
    3.61+    ; When displaying the number of clients and frames: 
    3.62+    ; subtract 1 from the clients for this client.
    3.63+    ; subtract 2 from the frames this frame (that we just created) and the default frame.
    3.64+    (when ( or (not active-clients-or-frames)
    3.65+	       (yes-or-no-p (format "There are currently %d clients and %d frames. Exit anyway?" 
    3.66+                                    (- (length server-clients) 1) (- (length (frame-list)) 2)))) 
    3.67+      ; If the user quits during the save dialog then don't exit emacs.
    3.68+      ; Still close the terminal though.
    3.69+      (let((inhibit-quit t))
    3.70+             ; Save buffers
    3.71+	(with-local-quit
    3.72+	  (save-some-buffers)) 
    3.73+	(if quit-flag
    3.74+	  (setq quit-flag nil)  
    3.75+          ; Kill all remaining clients
    3.76+	  (progn
    3.77+	    (dolist (client server-clients)
    3.78+	      (server-delete-client client))
    3.79+		 ; Exit emacs
    3.80+	    (kill-emacs)))))
    3.81+    ; If we made a frame then kill it.
    3.82+    (when (or modified-buffers active-clients-or-frames) (delete-frame new-frame))))
     4.1--- a/.stumpwm.d/init.lisp	Thu Aug 15 21:53:06 2024 -0400
     4.2+++ b/.stumpwm.d/init.lisp	Wed Aug 21 20:29:13 2024 -0400
     4.3@@ -2,13 +2,7 @@
     4.4 
     4.5 (in-package :stumpwm)
     4.6 
     4.7-;; (ql:quickload :swank)
     4.8-;; (require :swank)
     4.9-
    4.10-;; (defvar *stumpwm-port* 4040)
    4.11-;; (swank-loader:init)
    4.12-;; (swank:create-server :port *stumpwm-port*
    4.13-;;                      :style swank:*communication-style*)
    4.14+(stumpwm:set-prefix-key (kbd "s-SPC"))
    4.15 
    4.16 (defcommand load-std () ()
    4.17   (ql:quickload :std))
    4.18@@ -26,10 +20,23 @@
    4.19       *float-window-modifier* :SUPER
    4.20       *startup-message* "Greetings, stranger.")
    4.21 
    4.22-(set-font "-*-terminal")
    4.23-(set-module-dir "/usr/share/stupmwm/contrib/")
    4.24+(set-module-dir "~/.stumpwm.d/contrib")
    4.25 (init-load-path *module-dir*)
    4.26 
    4.27+(ql:quickload :clx-truetype)
    4.28+(load-module "ttf-fonts")
    4.29+(xft:cache-fonts)
    4.30+(set-font (make-instance 'xft:font
    4.31+            :family "Mononoki Nerd Font"
    4.32+            :subfamily "Regular"
    4.33+            :size 12))
    4.34+
    4.35+(load-module "swm-golden-ratio")
    4.36+(unless swm-golden-ratio:*golden-ratio-on*
    4.37+  (swm-golden-ratio:toggle-golden-ratio))
    4.38+
    4.39+(load-module "stumptray")
    4.40+
    4.41 (set-fg-color "#ffffff")
    4.42 (set-bg-color "#000000")
    4.43 (set-border-color "#7E5D90")
    4.44@@ -60,15 +67,15 @@
    4.45 (set-transient-gravity :center)
    4.46 (setf *time-modeline-string* "%a %b %e %k:%M")
    4.47 
    4.48-(setq *mode-line-timeout* 4)
    4.49-(which-key-mode)
    4.50+(setq *mode-line-timeout* 4)(
    4.51+which-key-mode)
    4.52 
    4.53 (when *initializing*
    4.54   (run-shell-command "sh ~/.fehbg")
    4.55   (when (equal (machine-instance) "zor")
    4.56     (run-shell-command "sh ~/.screenlayout/default.sh"))
    4.57-  (dolist (s stumpwm:*screen-list*) 
    4.58-    (enable-mode-line s (car (screen-heads s)) t)))
    4.59+  (dolist (h (screen-heads (current-screen)))
    4.60+    (enable-mode-line (current-screen) h t)))
    4.61 
    4.62 (defcommand term (&optional program) ()
    4.63   (sb-thread:make-thread
    4.64@@ -87,4 +94,7 @@
    4.65    (lambda ()
    4.66      (run-shell-command "chromium"))))
    4.67 
    4.68+(defcommand emacsclient () ()
    4.69+  (run-shell-command "emacsclient -c -a="))
    4.70+
    4.71 (define-key *root-map* (kbd "c") "term")