changelog shortlog graph tags branches changeset files revisions annotate raw help

Mercurial > infra > home / .emacs.d/lib/stumpwm-mode.el

changeset 86: a86cb552d6df
author: Richard Westhaver <ellis@rwest.io>
date: Wed, 21 Aug 2024 20:29:13 -0400
permissions: -rw-r--r--
description: stumpwm utils
1 ;;; stumpwm-mode.el --- special lisp mode for evaluating code into running stumpwm
2 
3 ;; Copyright (C) 2007 Shawn Betts
4 
5 ;; Maintainer: Shawn Betts
6 ;; Keywords: comm, lisp, tools
7 
8 ;; This file is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 2, or (at your option)
11 ;; any later version.
12 
13 ;; This file is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
17 
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GNU Emacs; see the file COPYING. If not, see
20 ;; <http://www.gnu.org/licenses/>.
21 
22 ;;; Commentary:
23 
24 ;; load this file, set stumpwm-shell-program to point to stumpish and
25 ;; run M-x stumpwm-mode in your stumpwm lisp files. Now, you can
26 ;; easily eval code into a running stumpwm using the regular bindings.
27 
28 ;;; Code:
29 
30 (defvar stumpwm-shell-program "stumpish"
31  "program name, including path if needed, for the stumpish program.")
32 
33 ;;;###autoload
34 (define-minor-mode stumpwm-mode
35  "add some bindings to eval code into a running stumpwm using stumpish."
36  :global nil
37  :lighter " StumpWM"
38  :keymap (let ((m (make-sparse-keymap)))
39  (define-key m (kbd "C-M-x") 'stumpwm-eval-defun)
40  (define-key m (kbd "C-x C-e") 'stumpwm-eval-last-sexp)
41  m))
42 
43 (defun stumpwm-eval-region (start end)
44  (interactive "r")
45  (let ((s (buffer-substring-no-properties start end)))
46  (message "%s"
47  (with-temp-buffer
48  (call-process stumpwm-shell-program nil (current-buffer) nil
49  "eval"
50  s)
51  (delete-char -1)
52  (buffer-string)))))
53 
54 (defun stumpwm-eval-defun ()
55  (interactive)
56  (save-excursion
57  (end-of-defun)
58  (skip-chars-backward " \t\n\r\f")
59  (let ((end (point)))
60  (beginning-of-defun)
61  (stumpwm-eval-region (point) end))))
62 
63 (defun stumpwm-eval-last-sexp ()
64  (interactive)
65  (stumpwm-eval-region (save-excursion (backward-sexp) (point)) (point)))
66 
67 (provide 'stumpwm-mode)
68 ;;; stumpwm-mode.el ends here