Skip to content
This repository

Use customize to simplify startup #12

Open
wants to merge 5 commits into from

1 participant

Daniel Hackney
Daniel Hackney
haxney commented May 03, 2012

By using define-minor-mode with an autoload cookie, smex can be loaded and initialized purely through Customize.

The old smex-initialize function has been removed, as its functionality is handled entirely within smex-mode.

This resolves issue #11

added some commits May 03, 2012
Daniel Hackney Add the minor mode `smex-mode'
Sets up the keymap for smex and can be set through `customize'. This can be used
instead of `smex-initialize'.
7cf2a15
Daniel Hackney Fix keymap format for `smex-major-mode-commands'
`[M-X]' just gets translated to "M-x"; to get the intended effect of "M-X", the
format is `[?\M-X]'
f6fc9b4
Daniel Hackney Modify docstrings to fit standard Emacs style.
The custom variables `smex-save-file' and `smex-history-length' no longer need
to be set early on. Initialization only takes place when `smex-mode' is turned
on, so those variables are read at that point (which is after customize has read
the values).
249d97f
Daniel Hackney Remove `smex-initialize' and `smex-initialize-ido'.
Their functionality is handled by `smex-mode'.
0cf05be
Daniel Hackney Clean up when `smex-mode' is disabled. bed1ed0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 5 unique commits by 1 author.

May 03, 2012
Daniel Hackney Add the minor mode `smex-mode'
Sets up the keymap for smex and can be set through `customize'. This can be used
instead of `smex-initialize'.
7cf2a15
Daniel Hackney Fix keymap format for `smex-major-mode-commands'
`[M-X]' just gets translated to "M-x"; to get the intended effect of "M-X", the
format is `[?\M-X]'
f6fc9b4
Daniel Hackney Modify docstrings to fit standard Emacs style.
The custom variables `smex-save-file' and `smex-history-length' no longer need
to be set early on. Initialization only takes place when `smex-mode' is turned
on, so those variables are read at that point (which is after customize has read
the values).
249d97f
Daniel Hackney Remove `smex-initialize' and `smex-initialize-ido'.
Their functionality is handled by `smex-mode'.
0cf05be
Daniel Hackney Clean up when `smex-mode' is disabled. bed1ed0
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 47 additions and 37 deletions. Show diff stats Hide diff stats

  1. 84  smex.el
84  smex.el
@@ -15,11 +15,12 @@
15 15
 
16 16
 ;;; Commentary:
17 17
 
18  
-;; Quick start:
19  
-;; run (smex-initialize)
  18
+;; Smex is a global minor mode which replaces `execute-extended-command' with
  19
+;; `smex', which uses `ido-mode' to provide enhanced completion.
20 20
 ;;
21  
-;; Bind the following commands:
22  
-;; smex, smex-major-mode-commands
  21
+;; To enable, set the custom variable `smex-mode' to a non-nil value.
  22
+;;
  23
+;; Smex can also be enabled manually by executing the function `smex-mode'.
23 24
 ;;
24 25
 ;; For a detailed introduction see:
25 26
 ;; http://github.com/nonsequitur/smex/blob/master/README.markdown
@@ -35,25 +36,23 @@
35 36
   :group 'extensions
36 37
   :group 'convenience
37 38
   :version "1.1"
  39
+  :prefix "smex-"
38 40
   :link '(emacs-library-link :tag "Lisp File" "smex.el"))
39 41
 
40 42
 (defcustom smex-auto-update t
41  
-  "If non-nil, `Smex' checks for new commands each time it is run.
  43
+  "If non-nil, `smex' checks for new commands each time it is run.
42 44
 Turn it off for minor speed improvements on older systems."
43 45
   :type 'boolean
44 46
   :group 'smex)
45 47
 
46 48
 (defcustom smex-save-file "~/.smex-items"
47 49
   "File in which the smex state is saved between Emacs sessions.
48  
-Variables stored are: `smex-data', `smex-history'.
49  
-Must be set before initializing Smex."
50  
-  :type 'string
  50
+Variables stored are: `smex-data', `smex-history'."
  51
+  :type 'file
51 52
   :group 'smex)
52 53
 
53 54
 (defcustom smex-history-length 7
54  
-  "Determines on how many recently executed commands
55  
-Smex should keep a record.
56  
-Must be set before initializing Smex."
  55
+  "Number of recently executed commands Smex records."
57 56
   :type 'integer
58 57
   :group 'smex)
59 58
 
@@ -63,13 +62,12 @@ Must be set before initializing Smex."
63 62
   :group 'smex)
64 63
 
65 64
 (defcustom smex-key-advice-ignore-menu-bar nil
66  
-  "If non-nil, `smex-key-advice' ignores `menu-bar' bindings"
  65
+  "If non-nil, `smex-key-advice' ignores `menu-bar' bindings."
67 66
   :type 'boolean
68 67
   :group 'smex)
69 68
 
70 69
 (defcustom smex-flex-matching t
71  
-  "Enables Ido flex matching. On by default.
72  
-Set this to nil to disable fuzzy matching."
  70
+  "Non-nil means enable Ido flex matching."
73 71
   :type 'boolean
74 72
   :group 'smex)
75 73
 
@@ -83,7 +81,40 @@ Set this to nil to disable fuzzy matching."
83 81
 ;;--------------------------------------------------------------------------------
84 82
 ;; Smex Interface
85 83
 
  84
+;;;###autoload
  85
+(define-minor-mode smex-mode "Minor mode to supercharge M-x.
  86
+When `smex-mode' is active, `execute-extended-command' is
  87
+remapped to `smex'. Built on top of Ido, it provides a convenient
  88
+interface to your recently and most frequently used commands. And
  89
+to all the other commands, too.
  90
+
  91
+No longer supports legacy save files; if you are still using the
  92
+old-style save file (\"~/smex.save\"), you will need to copy it
  93
+to the location in `smex-save-file'."
  94
+  :group 'smex
  95
+  :global t
  96
+  :require 'smex
  97
+  :keymap '(([remap execute-extended-command] . smex)
  98
+            ([?\M-X] . smex-major-mode-commands))
  99
+  (if smex-mode
  100
+      (progn
  101
+        (unless ido-mode (ido-common-initialization))
  102
+        (let ((save-file (expand-file-name smex-save-file)))
  103
+          (if (file-readable-p save-file)
  104
+              (with-temp-buffer
  105
+                (insert-file-contents save-file)
  106
+                (setq smex-history (read (current-buffer))
  107
+                      smex-data (read (current-buffer))))
  108
+            (setq smex-history nil
  109
+                  smex-data nil))
  110
+          (smex-detect-new-commands)
  111
+          (smex-rebuild-cache)
  112
+          (add-hook 'kill-emacs-hook 'smex-save-to-file))))
  113
+  (smex-save-to-file)
  114
+  (remove-hook 'kill-emacs-hook 'smex-save-to-file))
  115
+
86 116
 (defun smex ()
  117
+  "Read a function name using ido-enhanced search and call it."
87 118
   (interactive)
88 119
   (if (smex-already-running)
89 120
       (smex-update-and-rerun)
@@ -227,27 +258,6 @@ This function provides temporary means to aid the transition."
227 258
                          smex-save-file legacy-save-file))
228 259
         (setq smex-save-file legacy-save-file)))))
229 260
 
230  
-;;;###autoload
231  
-(defun smex-initialize ()
232  
-  (interactive)
233  
-  (unless ido-mode (smex-initialize-ido))
234  
-  (smex-detect-legacy-save-file)
235  
-  (let ((save-file (expand-file-name smex-save-file)))
236  
-    (if (file-readable-p save-file)
237  
-        (with-temp-buffer
238  
-          (insert-file-contents save-file)
239  
-          (setq smex-history (read (current-buffer))
240  
-                smex-data (read (current-buffer))))
241  
-      (setq smex-history nil smex-data nil))
242  
-    (smex-detect-new-commands)
243  
-    (smex-rebuild-cache)
244  
-    (add-hook 'kill-emacs-hook 'smex-save-to-file)))
245  
-
246  
-(defun smex-initialize-ido ()
247  
-  "Sets up a minimal Ido environment for `ido-completing-read'."
248  
-  (ido-init-completion-maps)
249  
-  (add-hook 'minibuffer-setup-hook 'ido-minibuffer-setup))
250  
-
251 261
 (defun smex-save-history ()
252 262
   "Updates `smex-history'"
253 263
   (setq smex-history nil)
@@ -436,13 +446,13 @@ Returns nil when reaching the end of the list."
436 446
   (let ((library-path (symbol-file mode))
437 447
         (mode-name (symbol-name mode))
438 448
         commands)
439  
-    
  449
+
440 450
     (string-match "\\(.+?\\)\\(-mode\\)?$" mode-name)
441 451
     ;; 'lisp-mode' -> 'lisp'
442 452
     (setq mode-name (match-string 1 mode-name))
443 453
     (if (string= mode-name "c") (setq mode-name "cc"))
444 454
     (setq mode-name (regexp-quote mode-name))
445  
-    
  455
+
446 456
     (dolist (feature load-history)
447 457
       (let ((feature-path (car feature)))
448 458
         (when (and feature-path (or (equal feature-path library-path)
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.