emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 7b9d755b81: Add new commands to elisp mode for eval/compilation


From: Lars Ingebrigtsen
Subject: master 7b9d755b81: Add new commands to elisp mode for eval/compilation
Date: Thu, 30 Jun 2022 06:01:02 -0400 (EDT)

branch: master
commit 7b9d755b816ca697b879b7c5c61526f96e9f4b9a
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Add new commands to elisp mode for eval/compilation
    
    * lisp/progmodes/elisp-mode.el (emacs-lisp-mode-map): Add new
    keystrokes.
    (elisp-eval-buffer, elisp-byte-compile-file)
    (elisp-byte-compile-buffer): New commands.
---
 etc/NEWS                     |  9 +++++++++
 lisp/progmodes/elisp-mode.el | 45 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+)

diff --git a/etc/NEWS b/etc/NEWS
index 14747eaf92..1ec9603640 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -983,6 +983,15 @@ so automatically.
 
 * Changes in Specialized Modes and Packages in Emacs 29.1
 
+** Elisp
+
+*** New command 'elisp-eval-buffer' (bound to 'C-c C-e').
+This command evals the forms in the the current buffer.
+
+*** New commands 'elisp-byte-compile-file' and 'elisp-byte-compile-buffer'.
+These commands (bound to 'C-c C-f' and 'C-c C-b', respectively)
+byte-compile the visited file and the current buffer, respectively.
+
 ** Games
 
 ---
diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el
index 0bf13a0e09..7acf7316a9 100644
--- a/lisp/progmodes/elisp-mode.el
+++ b/lisp/progmodes/elisp-mode.el
@@ -52,6 +52,9 @@ All commands in `lisp-mode-shared-map' are inherited by this 
map."
   :parent lisp-mode-shared-map
   "M-TAB" #'completion-at-point
   "C-M-x" #'eval-defun
+  "C-c C-e" #'elisp-eval-buffer
+  "C-c C-f" #'elisp-byte-compile-file
+  "C-c C-b" #'elisp-byte-compile-buffer
   "C-M-q" #'indent-pp-sexp)
 
 (easy-menu-define emacs-lisp-mode-menu emacs-lisp-mode-map
@@ -2194,6 +2197,48 @@ Runs in a batch-mode Emacs.  Interactively use variable
     (terpri)
     (pp collected)))
 
+(defun elisp-eval-buffer ()
+  "Evaluate the forms in the current buffer."
+  (interactive)
+  (eval-buffer)
+  (message "Evaluated the %s buffer" (buffer-name)))
+
+(defun elisp-byte-compile-file (&optional load)
+  "Byte compile the file the current buffer is visiting.
+If LOAD is non-nil, load the resulting .elc file.  When called
+interactively, this is the prefix argument."
+  (interactive "P")
+  (unless buffer-file-name
+    (error "This buffer is not visiting a file"))
+  (byte-compile-file buffer-file-name)
+  (when load
+    (load (funcall byte-compile-dest-file-function buffer-file-name))))
+
+(defun elisp-byte-compile-buffer (&optional load)
+  "Byte compile the current buffer, but don't write a file.
+If LOAD is non-nil, load byte-compiled data.  When called
+interactively, this is the prefix argument."
+  (interactive "P")
+  (let (file elc)
+    (unwind-protect
+        (progn
+          (setq file (make-temp-file "compile" nil ".el")
+                elc (funcall byte-compile-dest-file-function file))
+          (write-region (point-min) (point-max) file nil 'silent)
+          (let ((set-message-function
+                 (lambda (message)
+                   (when (string-match-p "\\`Wrote " message)
+                     'ignore))))
+            (byte-compile-file file))
+          (if load
+              (load elc)
+            (message "Byte-compiled the current buffer")))
+      (when file
+        (when (file-exists-p file)
+          (delete-file file))
+        (when (file-exists-p elc)
+          (delete-file elc))))))
+
 
 (put 'read-symbol-shorthands 'safe-local-variable #'consp)
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]