Skip to content

Commit 8c40191

Browse files
committed
Enable lexical bindings
1 parent da63713 commit 8c40191

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

smex.el

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
;;; smex.el --- M-x interface with Ido-style fuzzy matching.
1+
;;; smex.el --- M-x interface with Ido-style fuzzy matching. -*- lexical-binding: t; -*-
22

33
;; Copyright (C) 2009-2014 Cornelius Mika and contributors
44
;;
@@ -268,17 +268,20 @@ Set this to nil to disable fuzzy matching."
268268
"Updates `smex-history'"
269269
(setq smex-history nil)
270270
(let ((cell smex-cache))
271-
(dotimes (i smex-history-length)
271+
(dotimes (_ smex-history-length)
272272
(setq smex-history (cons (caar cell) smex-history))
273273
(setq cell (cdr cell))))
274274
(setq smex-history (nreverse smex-history)))
275275

276+
(defmacro smex-pp (list-var)
277+
`(smex-pp* ,list-var ,(symbol-name list-var)))
278+
276279
(defun smex-save-to-file ()
277280
(interactive)
278281
(smex-save-history)
279282
(with-temp-file (expand-file-name smex-save-file)
280-
(ido-pp 'smex-history)
281-
(ido-pp 'smex-data)))
283+
(smex-pp smex-history)
284+
(smex-pp smex-data)))
282285

283286
;;--------------------------------------------------------------------------------
284287
;; Ranking
@@ -340,8 +343,7 @@ Set this to nil to disable fuzzy matching."
340343
(defun smex-sort-item-at (n)
341344
"Sorts item at position N in `smex-cache'."
342345
(let* ((command-cell (nthcdr n smex-cache))
343-
(command-item (car command-cell))
344-
(command-count (cdr command-item)))
346+
(command-item (car command-cell)))
345347
(let ((insert-at (smex-detect-position
346348
command-cell
347349
(lambda (cell)
@@ -412,7 +414,7 @@ Returns nil when reaching the end of the list."
412414
commands))
413415

414416
(defun smex-parse-keymap (map commands)
415-
(map-keymap (lambda (binding element)
417+
(map-keymap (lambda (_binding element)
416418
(if (and (listp element) (eq 'keymap (car element)))
417419
(smex-parse-keymap element commands)
418420
;; Strings are commands, too. Reject them.
@@ -457,9 +459,25 @@ sorted by frequency of use."
457459
(setq buffer-read-only t)
458460
(let ((inhibit-read-only t))
459461
(erase-buffer)
460-
(ido-pp 'unbound-commands))
462+
(smex-pp unbound-commands))
461463
(set-buffer-modified-p nil)
462464
(goto-char (point-min))))
463465

466+
;; A copy of `ido-pp' that's compatible with lexical bindings
467+
(defun smex-pp* (list list-name)
468+
(let ((print-level nil) (eval-expression-print-level nil)
469+
(print-length nil) (eval-expression-print-length nil))
470+
(insert "\n;; ----- " list-name " -----\n(\n ")
471+
(while list
472+
(let* ((elt (car list))
473+
(s (if (consp elt) (car elt) elt)))
474+
(if (and (stringp s) (= (length s) 0))
475+
(setq s nil))
476+
(if s
477+
(prin1 elt (current-buffer)))
478+
(if (and (setq list (cdr list)) s)
479+
(insert "\n "))))
480+
(insert "\n)\n")))
481+
464482
(provide 'smex)
465483
;;; smex.el ends here

0 commit comments

Comments
 (0)