]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/progmodes/elisp-mode.el (elisp-enable-lexical-binding): New command
authorStefan Monnier <monnier@iro.umontreal.ca>
Tue, 3 Mar 2020 16:34:49 +0000 (11:34 -0500)
committerStefan Monnier <monnier@iro.umontreal.ca>
Tue, 3 Mar 2020 16:34:49 +0000 (11:34 -0500)
(emacs-lisp-mode): Indicate lex/dyn binding mode in the mode line.
(elisp--dynlex-modeline-map): New var.

lisp/progmodes/elisp-mode.el

index 813b628bc3588ee1252da8d5969f3f2e61bdcffb..20ec370dcb69e99cdd8c68fced8a124fe3b89680 100644 (file)
@@ -231,8 +231,35 @@ Comments in the form will be lost."
           (setq-local electric-pair-text-pairs elisp-pairs)))))
   (remove-hook 'electric-pair-mode-hook #'emacs-lisp-set-electric-text-pairs))
 
+(defun elisp-enable-lexical-binding (&optional interactive)
+  "Make the current buffer use `lexical-binding'."
+  (interactive "p")
+  (if lexical-binding
+      (when interactive
+        (message "lexical-binding already enabled!")
+        (ding))
+    (when (or (not interactive)
+              (y-or-n-p (format "Enable lexical-binding in this %s? "
+                                (if buffer-file-name "file" "buffer"))))
+      (setq-local lexical-binding t)
+      (add-file-local-variable-prop-line 'lexical-binding t interactive))))
+
+(defvar elisp--dynlex-modeline-map
+  (let ((map (make-sparse-keymap)))
+    (define-key map [mode-line mouse-1] 'elisp-enable-lexical-binding)
+    map))
+
 ;;;###autoload
-(define-derived-mode emacs-lisp-mode prog-mode "Emacs-Lisp"
+(define-derived-mode emacs-lisp-mode prog-mode
+  `("ELisp"
+    (lexical-binding (:propertize "/l"
+                      help-echo "Using lexical-binding mode")
+                     (:propertize "/d"
+                      help-echo "Using old dynamic scoping mode\n\
+mouse-1: Enable lexical-binding mode"
+                     face warning
+                     mouse-face mode-line-highlight
+                      local-map ,elisp--dynlex-modeline-map)))
   "Major mode for editing Lisp code to run in Emacs.
 Commands:
 Delete converts tabs to spaces as it moves back.
@@ -245,7 +272,7 @@ Blank lines separate paragraphs.  Semicolons start comments.
   (add-hook 'after-load-functions #'elisp--font-lock-flush-elisp-buffers)
   (if (boundp 'electric-pair-text-pairs)
       (setq-local electric-pair-text-pairs
-                  (append '((?\` . ?\') (?‘ . ?’))
+                  (append '((?\` . ?\') (?\‘ . ?\’))
                           electric-pair-text-pairs))
     (add-hook 'electric-pair-mode-hook #'emacs-lisp-set-electric-text-pairs))
   (setq-local electric-quote-string t)