From b69bcf34523551a93635bef90f0eb1d109c1076c Mon Sep 17 00:00:00 2001 From: Glenn Morris Date: Mon, 2 Oct 2017 13:19:11 -0400 Subject: ; * lisp/emacs-lisp/cl-print.el (cl-prin1): Whitespace fix. --- lisp/emacs-lisp/cl-print.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lisp/emacs-lisp') diff --git a/lisp/emacs-lisp/cl-print.el b/lisp/emacs-lisp/cl-print.el index 87c03280f77..4fc178c29aa 100644 --- a/lisp/emacs-lisp/cl-print.el +++ b/lisp/emacs-lisp/cl-print.el @@ -268,7 +268,7 @@ into a button whose action shows the function's disassembly.") Output is further controlled by the variables `cl-print-readably', `cl-print-compiled', along with output variables for the standard printing functions. See Info -node `(elisp)Output Variables'. " +node `(elisp)Output Variables'." (cond (cl-print-readably (prin1 object stream)) ((not print-circle) (cl-print-object object stream)) -- cgit v1.2.3 From 30ea272fe472ed77eab40179f43bb7bee5184912 Mon Sep 17 00:00:00 2001 From: João Távora Date: Sun, 1 Oct 2017 13:30:38 +0100 Subject: Hook Flymake onto proper checkdoc and byte-compile interfaces The interfaces in bytecomp.el and checkdoc.el are mostly boilerplate, with little knowledge of actual internals or thought given to the usefulness of said interfaces in contexts other than Flymake's. * lisp/emacs-lisp/bytecomp.el (byte-compile-log-warning-function): New variable. (byte-compile-log-warning): Use it. (byte-compile--log-warning-for-byte-compile): New function. * lisp/emacs-lisp/checkdoc.el (checkdoc-create-error-function): New variable. (checkdoc-create-error): Use it. (checkdoc--create-error-for-checkdoc): New function.xo * lisp/progmodes/flymake-elisp.el (flymake-elisp--checkdoc-1): Use checkdoc-create-error-function. (flymake-elisp--batch-byte-compile): Use byte-compile-log-warning-function. --- lisp/emacs-lisp/bytecomp.el | 22 ++++++++++++++++++++++ lisp/emacs-lisp/checkdoc.el | 19 ++++++++++++++++--- lisp/progmodes/flymake-elisp.el | 38 +++++++++++++++++++------------------- 3 files changed, 57 insertions(+), 22 deletions(-) (limited to 'lisp/emacs-lisp') diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el index 1b42961f1a4..590db570c56 100644 --- a/lisp/emacs-lisp/bytecomp.el +++ b/lisp/emacs-lisp/bytecomp.el @@ -1183,7 +1183,29 @@ Each function's symbol gets added to `byte-compile-noruntime-functions'." (compilation-forget-errors) pt)))) +(defvar byte-compile-log-warning-function + #'byte-compile--log-warning-for-byte-compile + "Function called when encountering a warning or error. +Called with arguments (STRING POSITION FILL LEVEL). STRING is a +message describing the problem. POSITION is a buffer position +where the problem was detected. FILL is a prefix as in +`warning-fill-prefix'. LEVEL is the level of the +problem (`:warning' or `:error'). POSITION, FILL and LEVEL may be +nil.") + (defun byte-compile-log-warning (string &optional fill level) + "Log a byte-compilation warning. +STRING, FILL and LEVEL are as described in +`byte-compile-log-warning-function', which see." + (funcall byte-compile-log-warning-function + string byte-compile-last-position + fill + level)) + +(defun byte-compile--log-warning-for-byte-compile (string &optional + _position + fill + level) "Log a message STRING in `byte-compile-log-buffer'. Also log the current function and file if not already done. If FILL is non-nil, set `warning-fill-prefix' to four spaces. LEVEL diff --git a/lisp/emacs-lisp/checkdoc.el b/lisp/emacs-lisp/checkdoc.el index 7997ba6014c..72f82f26f6f 100644 --- a/lisp/emacs-lisp/checkdoc.el +++ b/lisp/emacs-lisp/checkdoc.el @@ -1147,14 +1147,27 @@ Prefix argument is the same as for `checkdoc-defun'" ;; features and behaviors, so we need some ways of specifying ;; them, and making them easier to use in the wacked-out interfaces ;; people are requesting -(defun checkdoc-create-error (text start end &optional unfixable) - "Used to create the return error text returned from all engines. +(defvar checkdoc-create-error-function #'checkdoc--create-error-for-checkdoc + "Function called when Checkdoc encounters an error. +Should accept as arguments (TEXT START END &optional UNFIXABLE). + TEXT is the descriptive text of the error. START and END define the region it is sensible to highlight when describing the problem. Optional argument UNFIXABLE means that the error has no auto-fix available. A list of the form (TEXT START END UNFIXABLE) is returned if we are not -generating a buffered list of errors." +generating a buffered list of errors.") + +(defun checkdoc-create-error (text start end &optional unfixable) + "Used to create the return error text returned from all engines. +TEXT, START, END and UNFIXABLE conform to +`checkdoc-create-error-function', which see." + (funcall checkdoc-create-error-function text start end unfixable)) + +(defun checkdoc--create-error-for-checkdoc (text start end &optional unfixable) + "Create an error for Checkdoc. +TEXT, START, END and UNFIXABLE conform to +`checkdoc-create-error-function', which see." (if checkdoc-generate-compile-warnings-flag (progn (checkdoc-error start text) nil) diff --git a/lisp/progmodes/flymake-elisp.el b/lisp/progmodes/flymake-elisp.el index b42767c3fac..b433dc24e12 100644 --- a/lisp/progmodes/flymake-elisp.el +++ b/lisp/progmodes/flymake-elisp.el @@ -32,18 +32,18 @@ (defun flymake-elisp--checkdoc-1 () "Do actual work for `flymake-elisp-checkdoc'." (let (collected) - (cl-letf (((symbol-function 'checkdoc-create-error) - (lambda (text start end &optional unfixable) - (push (list text start end unfixable) collected) - nil))) - (let* ((checkdoc-autofix-flag nil) - (checkdoc-generate-compile-warnings-flag nil) - (buf (generate-new-buffer " *checkdoc-temp*")) - (checkdoc-diagnostic-buffer buf)) - (unwind-protect - (save-excursion - (checkdoc-current-buffer t)) - (kill-buffer buf)))) + (let* ((checkdoc-create-error-function + (lambda (text start end &optional unfixable) + (push (list text start end unfixable) collected) + nil)) + (checkdoc-autofix-flag nil) + (checkdoc-generate-compile-warnings-flag nil) + (buf (generate-new-buffer " *checkdoc-temp*")) + (checkdoc-diagnostic-buffer buf)) + (unwind-protect + (save-excursion + (checkdoc-current-buffer t)) + (kill-buffer buf))) collected)) ;;;###autoload @@ -165,14 +165,14 @@ Runs in a batch-mode Emacs. Interactively use variable (byte-compile-dest-file-function (lambda (source) (setq dummy-elc-file (make-temp-file (file-name-nondirectory source))))) - (collected)) + (collected) + (byte-compile-log-warning-function + (lambda (string &optional position fill level) + (push (list string position fill level) + collected) + t))) (unwind-protect - (cl-letf (((symbol-function 'byte-compile-log-warning) - (lambda (string &optional fill level) - (push (list string byte-compile-last-position fill level) - collected) - t))) - (byte-compile-file file)) + (byte-compile-file file) (ignore-errors (delete-file dummy-elc-file) (kill-buffer byte-compile-log-buffer))) -- cgit v1.2.3 From 3c4ff63bea662e2b89853894c5da69002a61ed5b Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Thu, 5 Oct 2017 12:41:36 +0300 Subject: Speed up list-packages when 'visual' line numbers are displayed * lisp/emacs-lisp/tabulated-list.el (tabulated-list-printer): Update the doc string. (tabulated-list-print-entry): Accept an additional optional argument INDENT. Update the doc string. (tabulated-list-print): Compute the width of line-number display once, then call tabulated-list-printer with that value as 3rd argument. (Bug#28704) --- lisp/emacs-lisp/tabulated-list.el | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'lisp/emacs-lisp') diff --git a/lisp/emacs-lisp/tabulated-list.el b/lisp/emacs-lisp/tabulated-list.el index e940588db7b..6c5874598ae 100644 --- a/lisp/emacs-lisp/tabulated-list.el +++ b/lisp/emacs-lisp/tabulated-list.el @@ -98,9 +98,12 @@ This is commonly used to recompute `tabulated-list-entries'.") (defvar-local tabulated-list-printer 'tabulated-list-print-entry "Function for inserting a Tabulated List entry at point. -It is called with two arguments, ID and COLS. ID is a Lisp -object identifying the entry, and COLS is a vector of column -descriptors, as documented in `tabulated-list-entries'.") +It is called with two mandatory arguments, ID and COLS, and one +optional argument, INDENT. ID is a Lisp object identifying the +entry, and COLS is a vector of column +descriptors, as documented in `tabulated-list-entries'. +INDENT, if present, is the initial indentation of the entry in +columns, it is used when `display-line-numbers' is in effect.") (defvar tabulated-list--near-rows) @@ -350,7 +353,7 @@ changing `tabulated-list-sort-key'." (funcall tabulated-list-entries) tabulated-list-entries)) (sorter (tabulated-list--get-sorter)) - entry-id saved-pt saved-col window-line) + entry-id saved-pt saved-col window-line lnum-width) (and remember-pos (setq entry-id (tabulated-list-get-id)) (setq saved-col (current-column)) @@ -371,6 +374,7 @@ changing `tabulated-list-sort-key'." (unless tabulated-list-use-header-line (tabulated-list-print-fake-header))) ;; Finally, print the resulting list. + (setq lnum-width (tabulated-list-line-number-width)) (while entries (let* ((elt (car entries)) (tabulated-list--near-rows @@ -383,9 +387,9 @@ changing `tabulated-list-sort-key'." (equal entry-id id) (setq entry-id nil saved-pt (point))) - ;; If the buffer this empty, simply print each elt. + ;; If the buffer is empty, simply print each elt. (if (or (not update) (eobp)) - (apply tabulated-list-printer elt) + (apply tabulated-list-printer (append elt (list lnum-width))) (while (let ((local-id (tabulated-list-get-id))) ;; If we find id, then nothing to update. (cond ((equal id local-id) @@ -398,7 +402,8 @@ changing `tabulated-list-sort-key'." ;; FIXME: Might be faster if ;; don't construct this list. (list local-id (tabulated-list-get-entry)))) - (apply tabulated-list-printer elt) + (apply tabulated-list-printer + (append elt (list lnum-width))) nil) ;; We find an entry that sorts before id, ;; it needs to be deleted. @@ -416,20 +421,22 @@ changing `tabulated-list-sort-key'." (recenter window-line))) (goto-char (point-min))))) -(defun tabulated-list-print-entry (id cols) +(defun tabulated-list-print-entry (id cols &optional indent) "Insert a Tabulated List entry at point. This is the default `tabulated-list-printer' function. ID is a Lisp object identifying the entry to print, and COLS is a vector -of column descriptors." +of column descriptors. +Optional argument INDENT is the initial indent of the entry, in +columns. This is used when `display-line-numbers' is in effect. +If INDENT is omitted or nil, it is treated as zero." (let ((beg (point)) (x (max tabulated-list-padding 0)) (ncols (length tabulated-list-format)) - (lnum-width (tabulated-list-line-number-width)) (inhibit-read-only t)) - (if display-line-numbers - (setq x (+ x lnum-width))) + (or indent (setq indent 0)) + (setq x (+ x indent)) (if (> tabulated-list-padding 0) - (insert (make-string (- x lnum-width) ?\s))) + (insert (make-string (- x indent) ?\s))) (let ((tabulated-list--near-rows ; Bind it if not bound yet (Bug#25506). (or (bound-and-true-p tabulated-list--near-rows) (list (or (tabulated-list-get-entry (point-at-bol 0)) -- cgit v1.2.3 From bd5326f879c089745c33871efc8682da5c206f80 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Thu, 5 Oct 2017 17:57:58 +0300 Subject: Fix breakage due to recent change in tabulated-list-print-entry * lisp/emacs-lisp/tabulated-list.el (tabulated-list-printer): Update the doc string. (tabulated-list-print-entry): Revert to using only 2 arguments. Update the doc string. (tabulated-list-entry-lnum-width): New defvar. (tabulated-list-print): Compute the width of line-number display once, then store that value in tabulated-list-entry-lnum-width, for tabulated-list-printer to use. (Bug#28704) --- lisp/emacs-lisp/tabulated-list.el | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) (limited to 'lisp/emacs-lisp') diff --git a/lisp/emacs-lisp/tabulated-list.el b/lisp/emacs-lisp/tabulated-list.el index 6c5874598ae..d1d7c0a8042 100644 --- a/lisp/emacs-lisp/tabulated-list.el +++ b/lisp/emacs-lisp/tabulated-list.el @@ -98,12 +98,9 @@ This is commonly used to recompute `tabulated-list-entries'.") (defvar-local tabulated-list-printer 'tabulated-list-print-entry "Function for inserting a Tabulated List entry at point. -It is called with two mandatory arguments, ID and COLS, and one -optional argument, INDENT. ID is a Lisp object identifying the -entry, and COLS is a vector of column -descriptors, as documented in `tabulated-list-entries'. -INDENT, if present, is the initial indentation of the entry in -columns, it is used when `display-line-numbers' is in effect.") +It is called with two arguments, ID and COLS. ID is a Lisp +object identifying the entry, and COLS is a vector of column +descriptors, as documented in `tabulated-list-entries'.") (defvar tabulated-list--near-rows) @@ -332,6 +329,8 @@ Check the current row, the previous one and the next row." (string-width (if (stringp nt) nt (car nt))))) tabulated-list--near-rows))) +(defvar tabulated-list-entry-lnum-width nil) + (defun tabulated-list-print (&optional remember-pos update) "Populate the current Tabulated List mode buffer. This sorts the `tabulated-list-entries' list if sorting is @@ -353,7 +352,7 @@ changing `tabulated-list-sort-key'." (funcall tabulated-list-entries) tabulated-list-entries)) (sorter (tabulated-list--get-sorter)) - entry-id saved-pt saved-col window-line lnum-width) + entry-id saved-pt saved-col window-line) (and remember-pos (setq entry-id (tabulated-list-get-id)) (setq saved-col (current-column)) @@ -374,7 +373,7 @@ changing `tabulated-list-sort-key'." (unless tabulated-list-use-header-line (tabulated-list-print-fake-header))) ;; Finally, print the resulting list. - (setq lnum-width (tabulated-list-line-number-width)) + (setq tabulated-list-entry-lnum-width (tabulated-list-line-number-width)) (while entries (let* ((elt (car entries)) (tabulated-list--near-rows @@ -389,7 +388,7 @@ changing `tabulated-list-sort-key'." saved-pt (point))) ;; If the buffer is empty, simply print each elt. (if (or (not update) (eobp)) - (apply tabulated-list-printer (append elt (list lnum-width))) + (apply tabulated-list-printer elt) (while (let ((local-id (tabulated-list-get-id))) ;; If we find id, then nothing to update. (cond ((equal id local-id) @@ -402,8 +401,7 @@ changing `tabulated-list-sort-key'." ;; FIXME: Might be faster if ;; don't construct this list. (list local-id (tabulated-list-get-entry)))) - (apply tabulated-list-printer - (append elt (list lnum-width))) + (apply tabulated-list-printer elt) nil) ;; We find an entry that sorts before id, ;; it needs to be deleted. @@ -421,22 +419,18 @@ changing `tabulated-list-sort-key'." (recenter window-line))) (goto-char (point-min))))) -(defun tabulated-list-print-entry (id cols &optional indent) +(defun tabulated-list-print-entry (id cols) "Insert a Tabulated List entry at point. This is the default `tabulated-list-printer' function. ID is a Lisp object identifying the entry to print, and COLS is a vector -of column descriptors. -Optional argument INDENT is the initial indent of the entry, in -columns. This is used when `display-line-numbers' is in effect. -If INDENT is omitted or nil, it is treated as zero." +of column descriptors." (let ((beg (point)) (x (max tabulated-list-padding 0)) (ncols (length tabulated-list-format)) (inhibit-read-only t)) - (or indent (setq indent 0)) - (setq x (+ x indent)) + (setq x (+ x tabulated-list-entry-lnum-width)) (if (> tabulated-list-padding 0) - (insert (make-string (- x indent) ?\s))) + (insert (make-string (- x tabulated-list-entry-lnum-width) ?\s))) (let ((tabulated-list--near-rows ; Bind it if not bound yet (Bug#25506). (or (bound-and-true-p tabulated-list--near-rows) (list (or (tabulated-list-get-entry (point-at-bol 0)) -- cgit v1.2.3 From 9a10c8713b8dd46738365d35263ae0687e2063cc Mon Sep 17 00:00:00 2001 From: Gemini Lasswell Date: Thu, 5 Oct 2017 12:41:35 -0700 Subject: Fix dynamic binding wrapper in iter-lambda (bug#25965) * lisp/emacs-lisp/generator.el (cps--make-dynamic-binding-wrapper): Remove extra evaluation of form. * test/lisp/emacs-lisp/generator-tests.el (cps-iter-lambda-with-dynamic-binding): New test. --- lisp/emacs-lisp/generator.el | 3 +-- test/lisp/emacs-lisp/generator-tests.el | 10 ++++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'lisp/emacs-lisp') diff --git a/lisp/emacs-lisp/generator.el b/lisp/emacs-lisp/generator.el index f3597cc387d..3e9885900cf 100644 --- a/lisp/emacs-lisp/generator.el +++ b/lisp/emacs-lisp/generator.el @@ -142,8 +142,7 @@ the CPS state machinery. `(let ((,dynamic-var ,static-var)) (unwind-protect ; Update the static shadow after evaluation is done ,form - (setf ,static-var ,dynamic-var)) - ,form))) + (setf ,static-var ,dynamic-var))))) (defmacro cps--with-dynamic-binding (dynamic-var static-var &rest body) "Evaluate BODY such that generated atomic evaluations run with diff --git a/test/lisp/emacs-lisp/generator-tests.el b/test/lisp/emacs-lisp/generator-tests.el index 4cc6c841dac..cbb136ae919 100644 --- a/test/lisp/emacs-lisp/generator-tests.el +++ b/test/lisp/emacs-lisp/generator-tests.el @@ -282,3 +282,13 @@ identical output. (ert-deftest cps-test-declarations-preserved () (should (equal (documentation 'generator-with-docstring) "Documentation!")) (should (equal (get 'generator-with-docstring 'lisp-indent-function) 5))) + +(ert-deftest cps-iter-lambda-with-dynamic-binding () + "`iter-lambda' with dynamic binding produces correct result (bug#25965)." + (should (= 1 + (iter-next + (funcall (iter-lambda () + (let* ((fill-column 10) ;;any special variable will do + (i 0) + (j (setq i (1+ i)))) + (iter-yield i)))))))) -- cgit v1.2.3