diff options
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r-- | lisp/emacs-lisp/eieio-opt.el | 2 | ||||
-rw-r--r-- | lisp/emacs-lisp/lisp.el | 36 | ||||
-rw-r--r-- | lisp/emacs-lisp/nadvice.el | 16 | ||||
-rw-r--r-- | lisp/emacs-lisp/package.el | 17 | ||||
-rw-r--r-- | lisp/emacs-lisp/timer.el | 80 |
5 files changed, 86 insertions, 65 deletions
diff --git a/lisp/emacs-lisp/eieio-opt.el b/lisp/emacs-lisp/eieio-opt.el index a502901a469..ca9b91bed58 100644 --- a/lisp/emacs-lisp/eieio-opt.el +++ b/lisp/emacs-lisp/eieio-opt.el @@ -141,7 +141,7 @@ If CLASS is actually an object, then also display current values of that object. (insert " " (aref type counter) " " (prin1-to-string (car cur) (current-buffer)) "\n" - (cdr cur))) + (or (cdr cur) ""))) (setq counter (1+ counter)))) (insert "\n\n") (setq methods (cdr methods)))))) diff --git a/lisp/emacs-lisp/lisp.el b/lisp/emacs-lisp/lisp.el index 3ff65ff11cd..23b021df177 100644 --- a/lisp/emacs-lisp/lisp.el +++ b/lisp/emacs-lisp/lisp.el @@ -431,16 +431,18 @@ is called as a function to find the defun's end." (push-mark)) (if (or (null arg) (= arg 0)) (setq arg 1)) (let ((pos (point)) - (beg (progn (end-of-line 1) (beginning-of-defun-raw 1) (point)))) + (beg (progn (end-of-line 1) (beginning-of-defun-raw 1) (point))) + (skip (lambda () + ;; When comparing point against pos, we want to consider that if + ;; point was right after the end of the function, it's still + ;; considered as "in that function". + ;; E.g. `eval-defun' from right after the last close-paren. + (unless (bolp) + (skip-chars-forward " \t") + (if (looking-at "\\s<\\|\n") + (forward-line 1)))))) (funcall end-of-defun-function) - ;; When comparing point against pos, we want to consider that if - ;; point was right after the end of the function, it's still - ;; considered as "in that function". - ;; E.g. `eval-defun' from right after the last close-paren. - (unless (bolp) - (skip-chars-forward " \t") - (if (looking-at "\\s<\\|\n") - (forward-line 1))) + (funcall skip) (cond ((> arg 0) ;; Moving forward. @@ -463,11 +465,19 @@ is called as a function to find the defun's end." (goto-char beg)) (unless (zerop arg) (beginning-of-defun-raw (- arg)) + (setq beg (point)) (funcall end-of-defun-function)))) - (unless (bolp) - (skip-chars-forward " \t") - (if (looking-at "\\s<\\|\n") - (forward-line 1))))) + (funcall skip) + (while (and (< arg 0) (>= (point) pos)) + ;; We intended to move backward, but this ended up not doing so: + ;; Try harder! + (goto-char beg) + (beginning-of-defun-raw (- arg)) + (if (>= (point) beg) + (setq arg 0) + (setq beg (point)) + (funcall end-of-defun-function) + (funcall skip))))) (defun mark-defun (&optional allow-extend) "Put mark at end of this defun, point at beginning. diff --git a/lisp/emacs-lisp/nadvice.el b/lisp/emacs-lisp/nadvice.el index 66a4f8fdea7..bfd939d69e2 100644 --- a/lisp/emacs-lisp/nadvice.el +++ b/lisp/emacs-lisp/nadvice.el @@ -180,12 +180,16 @@ WHERE is a symbol to select an entry in `advice--where-alist'." (advice--make-1 (nth 1 desc) (nth 2 desc) function main props))))) -(defun advice--member-p (function name definition) +(defun advice--member-p (function use-name definition) (let ((found nil)) (while (and (not found) (advice--p definition)) - (if (if name - (equal name (cdr (assq 'name (advice--props definition)))) - (equal function (advice--car definition))) + (if (if (eq use-name :use-both) + (or (equal function + (cdr (assq 'name (advice--props definition)))) + (equal function (advice--car definition))) + (equal function (if use-name + (cdr (assq 'name (advice--props definition))) + (advice--car definition)))) (setq found definition) (setq definition (advice--cdr definition)))) found)) @@ -292,7 +296,7 @@ is also interactive. There are 3 cases: ;;;###autoload (defun advice--add-function (where ref function props) (let* ((name (cdr (assq 'name props))) - (a (advice--member-p function name (gv-deref ref)))) + (a (advice--member-p (or name function) (if name t) (gv-deref ref)))) (when a ;; The advice is already present. Remove the old one, first. (setf (gv-deref ref) @@ -324,7 +328,7 @@ properties alist that was specified when it was added." "Return non-nil if ADVICE is already in FUNCTION-DEF. Instead of ADVICE being the actual function, it can also be the `name' of the piece of advice." - (advice--member-p advice advice function-def)) + (advice--member-p advice :use-both function-def)) ;;;; Specific application of add-function to `symbol-function' for advice. diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el index 5843724a596..e6bc8f9b485 100644 --- a/lisp/emacs-lisp/package.el +++ b/lisp/emacs-lisp/package.el @@ -1266,10 +1266,7 @@ similar to an entry in `package-alist'. Save the cached copy to ;; may fetch a URL redirect page). (when (listp (read (current-buffer))) (make-directory dir t) - (setq buffer-file-name (expand-file-name file dir)) - (let ((version-control 'never) - (require-final-newline nil)) - (save-buffer)))) + (write-region nil nil (expand-file-name file dir) nil 'silent))) (when good-signatures ;; Write out good signatures into archive-contents.signed file. (write-region (mapconcat #'epg-signature-to-string good-signatures "\n") @@ -1515,11 +1512,13 @@ If optional arg NO-ACTIVATE is non-nil, don't activate packages." (package--with-work-buffer (package-archive-base desc) (format "%s-readme.txt" name) - (setq buffer-file-name - (expand-file-name readme package-user-dir)) - (let ((version-control 'never) - (require-final-newline t)) - (save-buffer)) + (save-excursion + (goto-char (point-max)) + (unless (bolp) + (insert ?\n))) + (write-region nil nil + (expand-file-name readme package-user-dir) + nil 'silent) (setq readme-string (buffer-string)) t)) (error nil)) diff --git a/lisp/emacs-lisp/timer.el b/lisp/emacs-lisp/timer.el index 515bbc36a06..7fc6bf7b920 100644 --- a/lisp/emacs-lisp/timer.el +++ b/lisp/emacs-lisp/timer.el @@ -290,42 +290,50 @@ This function is called, by name, directly by the C code." (cell ;; Delete from queue. Record the cons cell that was used. (cancel-timer-internal timer))) - ;; Re-schedule if requested. - (if (timer--repeat-delay timer) - (if (timer--idle-delay timer) - (timer-activate-when-idle timer nil cell) - (timer-inc-time timer (timer--repeat-delay timer) 0) - ;; If real time has jumped forward, - ;; perhaps because Emacs was suspended for a long time, - ;; limit how many times things get repeated. - (if (and (numberp timer-max-repeats) - (< 0 (timer-until timer (current-time)))) - (let ((repeats (/ (timer-until timer (current-time)) - (timer--repeat-delay timer)))) - (if (> repeats timer-max-repeats) - (timer-inc-time timer (* (timer--repeat-delay timer) - repeats))))) - ;; Place it back on the timer-list before running - ;; timer--function, so it can cancel-timer itself. - (timer-activate timer t cell) - (setq retrigger t))) - ;; Run handler. - (condition-case-unless-debug err - ;; Timer functions should not change the current buffer. - ;; If they do, all kinds of nasty surprises can happen, - ;; and it can be hellish to track down their source. - (save-current-buffer - (apply (timer--function timer) (timer--args timer))) - (error (message "Error running timer%s: %S" - (if (symbolp (timer--function timer)) - (format " `%s'" (timer--function timer)) "") - err))) - (when (and retrigger - ;; If the timer's been canceled, don't "retrigger" it - ;; since it might still be in the copy of timer-list kept - ;; by keyboard.c:timer_check (bug#14156). - (memq timer timer-list)) - (setf (timer--triggered timer) nil))))) + ;; If `cell' is nil, it means the timer was already canceled, so we + ;; shouldn't be running it at all. This can happen for example with the + ;; following scenario (bug#17392): + ;; - we run timers, starting with A (and remembering the rest as (B C)). + ;; - A runs and a does a sit-for. + ;; - during sit-for we run timer D which cancels timer B. + ;; - timer A finally finishes, so we move on to timers B and C. + (when cell + ;; Re-schedule if requested. + (if (timer--repeat-delay timer) + (if (timer--idle-delay timer) + (timer-activate-when-idle timer nil cell) + (timer-inc-time timer (timer--repeat-delay timer) 0) + ;; If real time has jumped forward, + ;; perhaps because Emacs was suspended for a long time, + ;; limit how many times things get repeated. + (if (and (numberp timer-max-repeats) + (< 0 (timer-until timer (current-time)))) + (let ((repeats (/ (timer-until timer (current-time)) + (timer--repeat-delay timer)))) + (if (> repeats timer-max-repeats) + (timer-inc-time timer (* (timer--repeat-delay timer) + repeats))))) + ;; Place it back on the timer-list before running + ;; timer--function, so it can cancel-timer itself. + (timer-activate timer t cell) + (setq retrigger t))) + ;; Run handler. + (condition-case-unless-debug err + ;; Timer functions should not change the current buffer. + ;; If they do, all kinds of nasty surprises can happen, + ;; and it can be hellish to track down their source. + (save-current-buffer + (apply (timer--function timer) (timer--args timer))) + (error (message "Error running timer%s: %S" + (if (symbolp (timer--function timer)) + (format " `%s'" (timer--function timer)) "") + err))) + (when (and retrigger + ;; If the timer's been canceled, don't "retrigger" it + ;; since it might still be in the copy of timer-list kept + ;; by keyboard.c:timer_check (bug#14156). + (memq timer timer-list)) + (setf (timer--triggered timer) nil)))))) ;; This function is incompatible with the one in levents.el. (defun timeout-event-p (event) |