├── README.creole └── lisp-editing.el /README.creole: -------------------------------------------------------------------------------- 1 | Some lisp editing tools. I don't know where else to put them. 2 | 3 | They probably need renaming because they pollute the {{{lisp-}}} namespace 4 | in Emacs but for now... hey. 5 | 6 | 7 | === lisp-lexbind-modeline === 8 | 9 | Add LEX to the modeline. 10 | 11 | 12 | === lisp-lexscratch &optional other-window === 13 | 14 | Make a lexical scratch buffer. 15 | 16 | 17 | === lisp-load-all filename === 18 | 19 | Load all the files in a package. 20 | 21 | Takes a filename that specifies all the files in a package. 22 | 23 | 24 | === lisp-package-time-now === 25 | 26 | Produce the current time in a package friendly format. 27 | 28 | If called interactively it inserts at point. 29 | 30 | 31 | === lisp-reinsert-as-pp === 32 | 33 | Read sexp at point, delete it and pretty print it back in. 34 | 35 | 36 | -------------------------------------------------------------------------------- /lisp-editing.el: -------------------------------------------------------------------------------- 1 | ;;; lisp-editing.el --- lisp editing tools 2 | 3 | ;; Copyright (C) 2012 Nic Ferrier 4 | 5 | ;; Author: Nic Ferrier 6 | ;; Maintainer: Nic Ferrier 7 | ;; Created: 18th August 2012 8 | ;; Keywords: lisp 9 | ;; Version: 0.0.6 10 | ;; Url: http://github.com/nicferrier/emacs-lisp-editing-tools 11 | 12 | ;; This program is free software; you can redistribute it and/or modify 13 | ;; it under the terms of the GNU General Public License as published by 14 | ;; the Free Software Foundation, either version 3 of the License, or 15 | ;; (at your option) any later version. 16 | 17 | ;; This program is distributed in the hope that it will be useful, 18 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | ;; GNU General Public License for more details. 21 | 22 | ;; You should have received a copy of the GNU General Public License 23 | ;; along with this program. If not, see . 24 | 25 | ;;; Commentary: 26 | 27 | ;; Some lisp editing tools. 28 | 29 | ;;; Code: 30 | 31 | (require 'pp) 32 | 33 | (defun lisp-package-time-now () 34 | "Produce the current time in a package friendly format. 35 | 36 | If called interactively it inserts at point." 37 | (interactive) 38 | (let ((time-str 39 | (format-time-string 40 | (format 41 | "%%d%s %%B %%Y" 42 | (let ((day (string-to-number (format-time-string "%d")))) 43 | (if 44 | (or (and (<= 4 day) (<= day 20)) 45 | (and (<= 24 day) (<= day 30))) 46 | "th" 47 | ;; Else one of the others 48 | (elt ["st" "nd" "rd"] (- (% day 10) 1)))))))) 49 | (if (called-interactively-p 'interactive) 50 | (insert time-str) 51 | time-str))) 52 | 53 | 54 | (defun lisp-lexbind-modeline () 55 | "Add LEX to the modeline." 56 | ;; not sure about this: mode-line-modes is a cust var 57 | ;; we're breaking customization by doing this 58 | (interactive) 59 | (add-to-list 60 | 'mode-line-modes 61 | '(:eval 62 | (when lexical-binding "LEX")))) 63 | 64 | (defun lisp-lexscratch (&optional other-window) 65 | "Make a lexical scratch buffer." 66 | (interactive "P") 67 | (let ((buf (get-buffer "*lexscratch*"))) 68 | (unless buf 69 | (setq buf (get-buffer-create "*lexscratch*")) 70 | (with-current-buffer buf 71 | (lisp-interaction-mode) 72 | (setq lexical-binding t) 73 | (insert initial-scratch-message))) 74 | (if other-window 75 | (switch-to-buffer-other-window buf) 76 | (switch-to-buffer buf)))) 77 | 78 | ;;;###autoload 79 | (defun lisp-reinsert-as-pp () 80 | "Read sexp at point, delete it and pretty print it back in." 81 | (interactive) 82 | (let* ((buf (current-buffer)) 83 | (pp-sexp 84 | (replace-regexp-in-string 85 | "\\(\n\\)$" 86 | "" 87 | (with-temp-buffer 88 | (let ((bufname (buffer-name))) 89 | (pp-display-expression 90 | (with-current-buffer buf 91 | (car 92 | (read-from-string 93 | (replace-regexp-in-string 94 | "\\*\\(.*?\\)\\*\\(<[0-9]+>\\)* <[0-9:.]+>" 95 | "\"\\&\"" 96 | (save-excursion 97 | (buffer-substring-no-properties 98 | (point) 99 | (progn 100 | (forward-sexp) 101 | (point)))))))) 102 | bufname) 103 | (buffer-substring (point-min) (point-max))))))) 104 | (kill-sexp) 105 | (insert pp-sexp))) 106 | 107 | ;;;###autoload 108 | (defun lisp-load-all (filename) 109 | "Load all the files in a package. 110 | 111 | Takes a filename that specifies all the files in a package." 112 | (interactive "Gfile list:") 113 | (flet ((map-regex (buffer regex fn) 114 | "Map the REGEX over the BUFFER executing FN. 115 | 116 | FN is called with the match-data of the regex. 117 | 118 | Returns the results of the FN as a list." 119 | (with-current-buffer buffer 120 | (save-excursion 121 | (goto-char (point-min)) 122 | (let (res) 123 | (save-match-data 124 | (while (re-search-forward regex nil t) 125 | (let ((f (match-data))) 126 | (setq res 127 | (append res 128 | (list 129 | (save-match-data 130 | (funcall fn f)))))))) 131 | res))))) 132 | (map-regex 133 | (find-file-noselect 134 | (cond 135 | ((and filename 136 | (file-exists-p filename) 137 | (file-directory-p filename)) 138 | (concat (file-name-as-directory filename) "build-parts.txt")) 139 | ((file-exists-p filename) 140 | filename))) 141 | "^\\(.*.el\\(\\.gz\\)*\\)$" 142 | (lambda (md) 143 | (let ((filename (match-string 0))) 144 | (message "loading %s" filename) 145 | (when (file-exists-p filename) 146 | (load-file filename))))))) 147 | 148 | 149 | (provide 'lisp-editing) 150 | 151 | ;;; lisp-editing.el ends here 152 | --------------------------------------------------------------------------------