paredit-menu.el (4115B)
1 ;;; paredit-menu.el --- Adds a menu to paredit.el as memory aid 2 3 ;; This file is not part of Emacs 4 5 ;; Author: Phillip Lord <phillip.lord@newcastle.ac.uk> 6 ;; Maintainer: Phillip Lord <phillip.lord@newcastle.ac.uk> 7 ;; Keywords: paredit 8 ;; Package-Version: 20160128.1733 9 ;; Package-Commit: cc0ae85bd819f9ebfa4f2a419ab3b2d70e39c9c8 10 ;; Version: 1.0 11 ;; Package-Requires: ((paredit "25")) 12 13 ;; COPYRIGHT NOTICE 14 ;; 15 ;; This program is free software; you can redistribute it and/or modify 16 ;; it under the terms of the GNU General Public License as published by 17 ;; the Free Software Foundation; either version 2, or (at your option) 18 ;; any later version. 19 20 ;; This program is distributed in the hope that it will be useful, 21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 ;; GNU General Public License for more details. 24 25 ;; You should have received a copy of the GNU General Public License 26 ;; along with this program; see the file COPYING. If not, write to the 27 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, 28 ;; Boston, MA 02111-1307, USA. 29 30 ;;; Commentary: 31 ;; 32 ;; Paredit mode provides structured editing for Lisp. It achieves this by 33 ;; ensuring that code is always well-formed while editing. While it is very 34 ;; helpful, sometimes it leaves the less experienced user (such as the myself) 35 ;; scratching their head over how to achieve a simple editing task. 36 37 ;; One solution is to use the cheatsheet 38 ;; (http://emacswiki.org/emacs/PareditCheatsheet). However, this is outside 39 ;; Emacs and does not scale well. This file provides a second solution, which 40 ;; is a menu. While slower than using the equivalent key-presses, it provides 41 ;; an easy mechanism to look up the relevant commands. Tooltips are also 42 ;; provided showing the examples of use. 43 44 ;; Documentation and examples come directly from paredit, so the menu should 45 ;; automatically stay in sync, regardless of changes to paredit. 46 47 ;;; Installation: 48 ;; 49 ;; Add (require 'paredit-menu) to your .emacs. This will also force loading of 50 ;; paredit. If you autoload paredit, then 51 ;; 52 ;; (eval-after-load "paredit.el" 53 ;; '(require 'paredit-menu)) 54 ;; 55 ;; will achieve the same effect. 56 57 58 (require 'paredit) 59 60 ;;; Code: 61 62 (defun paredit-menu-build-menu () 63 "Builds the menu from `paredit-commands'." 64 (cons "Paredit" 65 (paredit-menu-build-menu-1 paredit-commands nil nil))) 66 67 (defun paredit-menu-build-menu-1 (commands menu submenu) 68 "Really builds the menu. 69 70 COMMANDS is the list of commands remaining to add 71 MENU is the current menu 72 SUBMENU is the current submenu" 73 (let ((first (car commands)) 74 (rest (cdr commands))) 75 ;; drop last submenu in place and complete 76 (if (not first) 77 (append menu (list submenu)) 78 ;; is a submenu title 79 (if (stringp first) 80 ;; start a new submenu 81 (paredit-menu-build-menu-1 82 rest 83 ;; appending the last submenu if it exists 84 (if submenu 85 (append menu (list submenu)) 86 menu) 87 (list first)) 88 ;; we have a command 89 (paredit-menu-build-menu-1 90 rest menu 91 (append submenu 92 (list (vector (paredit-menu-symbol-name 93 (symbol-name (nth 1 first))) 94 (nth 1 first) 95 :help (paredit-menu-help-string first))))))))) 96 97 98 (defun paredit-menu-symbol-name (name) 99 "Generate display name from symbol name. 100 101 No point putting \"paredit\" on the front of everything, so chop 102 this off. 103 104 NAME is the symbol name." 105 (substring name 8)) 106 107 (defun paredit-menu-help-string (command) 108 "Generate help string for command. 109 110 COMMAND is the command" 111 (let ((string 112 (mapconcat 113 (lambda (x) 114 (format "%s -> \n\t%s" (nth 0 x) (nth 1 x)) 115 ) 116 (cddr command) "\n\n"))) 117 (if (eq "" string) 118 "No Example" 119 string))) 120 121 122 (easy-menu-define menubar-paredit paredit-mode-map "paredit" 123 (paredit-menu-build-menu)) 124 125 (provide 'paredit-menu) 126 127 ;;; paredit-menu.el ends here