commit 137b65a9b0a4118adda50f34375b4960701542e9 (HEAD, refs/remotes/origin/master) Author: Juri Linkov Date: Mon Jan 28 23:17:04 2019 +0200 Small fixes * lisp/generic-x.el (etc-passwd-generic-mode): Add comment. (Bug#34225) * lisp/vc/diff-mode.el (diff-syntax-fontify-hunk): Set overlay property 'diff-mode to 'syntax. (Bug#33567) (diff-syntax-fontify-props): Reset buffer-file-name to nil. diff --git a/lisp/generic-x.el b/lisp/generic-x.el index dd61402015..47dfd2822d 100644 --- a/lisp/generic-x.el +++ b/lisp/generic-x.el @@ -1490,6 +1490,7 @@ like an INI file. You can add this hook to `find-file-hook'." '("^\\([^:]+\\):\\([^:]*\\):\\([0-9]+\\):\\(.*\\)$" (1 font-lock-type-face) (4 font-lock-variable-name-face)))) + ;; /etc/passwd- is a backup file for /etc/passwd, so is group- and shadow- '("/etc/passwd-?\\'" "/etc/group-?\\'" "/etc/shadow-?\\'") (list (function diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el index 5d6cc6f38f..158489c97f 100644 --- a/lisp/vc/diff-mode.el +++ b/lisp/vc/diff-mode.el @@ -2488,6 +2488,7 @@ When OLD is non-nil, highlight the hunk from the old source." (let ((ol (make-overlay (+ bol (nth 0 prop)) (+ bol (nth 1 prop)) nil 'front-advance nil))) + (overlay-put ol 'diff-mode 'syntax) (overlay-put ol 'evaporate t) (overlay-put ol 'face (nth 2 prop)))))))))))) @@ -2502,6 +2503,7 @@ hunk text is not found in the source file." (unless no-init (buffer-disable-undo) (font-lock-mode -1) + (setq buffer-file-name nil) (let ((enable-local-variables :safe) ;; to find `mode:' (buffer-file-name file)) (set-auto-mode) commit 020f6233721661059990a4239b94cd7b64396f03 Author: Glenn Morris Date: Mon Jan 28 15:55:57 2019 -0500 * src/Makefile.in (clean): Delete versioned pdmp files. Else build number increments without limit even in clean builds. diff --git a/src/Makefile.in b/src/Makefile.in index 5890eac8c6..ee27db0811 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -690,7 +690,8 @@ mostlyclean: rm -f globals.h gl-stamp rm -f ./*.res ./*.tmp clean: mostlyclean - rm -f emacs-*.*.*[0-9]$(EXEEXT) emacs$(EXEEXT) $(DEPDIR)/* + rm -f emacs-*.*.*[0-9]$(EXEEXT) emacs-*.*.*[0-9].pdmp + rm -f emacs$(EXEEXT) $(DEPDIR)/* ## bootstrap-clean is used to clean up just before a bootstrap. ## It should remove all files generated during a compilation/bootstrap, commit 0f94d422f16cc989f49ea5c7fc87c947c5f42ced Author: Juri Linkov Date: Mon Jan 28 22:27:22 2019 +0200 More checks for live buffers. * lisp/dired-x.el (dired-jump): Check if archive/tar superior buffer was killed by the user. * lisp/progmodes/ruby-mode.el (ruby-flymake--helper): Check if source buffer was killed by the user immediately after visiting and before process finishes. diff --git a/lisp/dired-x.el b/lisp/dired-x.el index 44e73759fa..defc541ddc 100644 --- a/lisp/dired-x.el +++ b/lisp/dired-x.el @@ -463,9 +463,11 @@ Interactively with prefix argument, read FILE-NAME." (list nil (and current-prefix-arg (read-file-name "Jump to Dired file: ")))) (cond - ((bound-and-true-p archive-subfile-mode) + ((and (bound-and-true-p archive-subfile-mode) + (buffer-live-p archive-superior-buffer)) (switch-to-buffer archive-superior-buffer)) - ((bound-and-true-p tar-subfile-mode) + ((and (bound-and-true-p tar-subfile-mode) + (buffer-live-p tar-superior-buffer)) (switch-to-buffer tar-superior-buffer)) (t ;; Expand file-name before `dired-goto-file' call: diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el index 8aa583eb31..e83778af94 100644 --- a/lisp/progmodes/ruby-mode.el +++ b/lisp/progmodes/ruby-mode.el @@ -2288,7 +2288,7 @@ It will be properly highlighted even when the call omits parens.") :command command :sentinel (lambda (proc _event) - (when (eq 'exit (process-status proc)) + (when (and (eq 'exit (process-status proc)) (buffer-live-p source)) (unwind-protect (if (with-current-buffer source (eq proc ruby--flymake-proc)) (with-current-buffer (process-buffer proc) commit 599eee3ebefa4e1c7c6610e5629090ad7ad5159b Author: Juri Linkov Date: Mon Jan 28 22:18:20 2019 +0200 * lisp/generic-x.el (etc-passwd-generic-mode): Support backups of passwd, group and shadow /etc files. (Bug#34225) diff --git a/lisp/generic-x.el b/lisp/generic-x.el index 014379fba9..dd61402015 100644 --- a/lisp/generic-x.el +++ b/lisp/generic-x.el @@ -1490,7 +1490,7 @@ like an INI file. You can add this hook to `find-file-hook'." '("^\\([^:]+\\):\\([^:]*\\):\\([0-9]+\\):\\(.*\\)$" (1 font-lock-type-face) (4 font-lock-variable-name-face)))) - '("/etc/passwd\\'" "/etc/group\\'") + '("/etc/passwd-?\\'" "/etc/group-?\\'" "/etc/shadow-?\\'") (list (function (lambda () commit 9d8f900d93c196cd1048cdbad12e08da7a38a604 Author: Eli Zaretskii Date: Mon Jan 28 22:03:05 2019 +0200 Fix last change in xfaces.c * src/xfaces.c (init_xfaces): Don't rely of 'face' property of a face to be a natural number. diff --git a/src/xfaces.c b/src/xfaces.c index 7facb13b76..3ba824b651 100644 --- a/src/xfaces.c +++ b/src/xfaces.c @@ -6520,28 +6520,19 @@ init_xfaces (void) { if (CONSP (Vface_new_frame_defaults)) { - Lisp_Object lface = XCAR (Vface_new_frame_defaults); - if (CONSP (lface)) + /* Allocate the lface_id_to_name[] array. */ + lface_id_to_name_size = next_lface_id = + XFIXNAT (Flength (Vface_new_frame_defaults)); + lface_id_to_name = xnmalloc (next_lface_id, sizeof *lface_id_to_name); + + /* Store the faces. */ + Lisp_Object tail; + int i = next_lface_id - 1; + for (tail = Vface_new_frame_defaults; CONSP (tail); tail = XCDR (tail)) { - /* The first face in the list is the last face defined - during loadup. Compute how many faces are there, and - allocate the lface_id_to_name[] array. */ - Lisp_Object lface_id = Fget (XCAR (lface), Qface); - lface_id_to_name_size = next_lface_id = XFIXNAT (lface_id) + 1; - lface_id_to_name = xnmalloc (next_lface_id, sizeof *lface_id_to_name); - /* Store the last face. */ - lface_id_to_name[next_lface_id - 1] = lface; - - /* Store the rest of the faces. */ - Lisp_Object tail; - for (tail = XCDR (Vface_new_frame_defaults); CONSP (tail); - tail = XCDR (tail)) - { - lface = XCAR (tail); - int face_id = XFIXNAT (Fget (XCAR (lface), Qface)); - eassert (face_id < lface_id_to_name_size); - lface_id_to_name[face_id] = lface; - } + Lisp_Object lface = XCAR (tail); + eassert (i >= 0); + lface_id_to_name[i--] = XCAR (lface); } } } commit 0c9bce3fc490d6f5e935883e9690871cce4f9150 Author: Michael Albinus Date: Mon Jan 28 16:33:47 2019 +0100 * test/lisp/net/tramp-tests.el (tramp-test03-file-name-defaults): Adapt test. diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el index 5adc6b1a14..7fa25f1baf 100644 --- a/test/lisp/net/tramp-tests.el +++ b/test/lisp/net/tramp-tests.el @@ -1817,17 +1817,15 @@ properly. BODY shall not contain a timeout." (should (string-equal (file-remote-p "/-:ftp.host:" 'method) "ftp")) (dolist (u '("ftp" "anonymous")) (should (string-equal (file-remote-p (format "/-:%s@:" u) 'method) "ftp"))) - ;; Default values in tramp-gvfs.el. - (when (and (load "tramp-gvfs" 'noerror 'nomessage) - (symbol-value 'tramp-gvfs-enabled)) - (should (string-equal (file-remote-p "/synce::" 'user) nil))) - ;; Default values in tramp-sh.el. + ;; Default values in tramp-sh.el and tramp-sudoedit.el. (dolist (h `("127.0.0.1" "[::1]" "localhost" "localhost6" ,(system-name))) (should (string-equal (file-remote-p (format "/-:root@%s:" h) 'method) "su"))) - (dolist (m '("su" "sudo" "ksu")) - (should (string-equal (file-remote-p (format "/%s::" m) 'user) "root"))) - (dolist (m '("rcp" "remcp" "rsh" "telnet" "krlogin" "fcp")) + (dolist (m '("su" "sudo" "ksu" "doas" "sudoedit")) + (should (string-equal (file-remote-p (format "/%s::" m) 'user) "root")) + (should + (string-equal (file-remote-p (format "/%s::" m) 'host) (system-name)))) + (dolist (m '("rcp" "remcp" "rsh" "telnet" "krlogin" "fcp" "nc")) (should (string-equal (file-remote-p (format "/%s::" m) 'user) (user-login-name)))) ;; Default values in tramp-smb.el. commit 6c560a3b16f9015a19044395f0ef41b718d73496 Author: Michael Albinus Date: Mon Jan 28 16:33:27 2019 +0100 Adapt accept-process-output timeouts in Tramp * lisp/net/tramp.el (tramp-accept-process-output): Make timeout optional. Do not set explicit timer. (tramp-action-out-of-band, tramp-process-one-action) (tramp-wait-for-regexp, tramp-interrupt-process): * lisp/net/tramp-adb.el (tramp-adb-parse-device-names): * lisp/net/tramp-gvfs.el (tramp-gvfs-handle-file-notify-add-watch): * lisp/net/tramp-rclone.el (tramp-rclone-parse-device-names): * lisp/net/tramp-sh.el (tramp-sh-handle-file-notify-add-watch): * lisp/net/tramp-smb.el (tramp-smb-action-get-acl) (tramp-smb-action-set-acl, tramp-smb-wait-for-output): * tramp-sudoedit.el (tramp-sudoedit-action-sudo): Adapt `accept-process-output' calls wrt timeouts. diff --git a/lisp/net/tramp-adb.el b/lisp/net/tramp-adb.el index c900d3c9a2..372ce15414 100644 --- a/lisp/net/tramp-adb.el +++ b/lisp/net/tramp-adb.el @@ -206,8 +206,7 @@ pass to the OPERATION." (tramp-message v 6 "%s" (mapconcat 'identity (process-command p) " ")) (process-put p 'adjust-window-size-function 'ignore) (set-process-query-on-exit-flag p nil) - (while (or (accept-process-output p 0.1) - (process-live-p p))) + (while (accept-process-output p nil nil t)) (tramp-message v 6 "\n%s" (buffer-string)) (goto-char (point-min)) (while (search-forward-regexp "^\\(\\S-+\\)[[:space:]]+device$" nil t) diff --git a/lisp/net/tramp-gvfs.el b/lisp/net/tramp-gvfs.el index f6ff37b4ee..1f1454925c 100644 --- a/lisp/net/tramp-gvfs.el +++ b/lisp/net/tramp-gvfs.el @@ -1186,7 +1186,7 @@ If FILE-SYSTEM is non-nil, return file system attributes." (set-process-filter p 'tramp-gvfs-monitor-process-filter) ;; There might be an error if the monitor is not supported. ;; Give the filter a chance to read the output. - (tramp-accept-process-output p 1) + (while (tramp-accept-process-output p)) (unless (process-live-p p) (tramp-error p 'file-notify-error "Monitoring not supported for `%s'" file-name)) diff --git a/lisp/net/tramp-rclone.el b/lisp/net/tramp-rclone.el index f5d184af69..bc48d4d3a8 100644 --- a/lisp/net/tramp-rclone.el +++ b/lisp/net/tramp-rclone.el @@ -183,8 +183,7 @@ pass to the OPERATION." (tramp-message v 6 "%s" (mapconcat 'identity (process-command p) " ")) (process-put p 'adjust-window-size-function 'ignore) (set-process-query-on-exit-flag p nil) - (while (or (accept-process-output p 0.1) - (process-live-p p))) + (while (accept-process-output p nil nil t)) (tramp-message v 6 "\n%s" (buffer-string)) (goto-char (point-min)) (while (search-forward-regexp "^\\(\\S-+\\):$" nil t) diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el index c578a73f46..e4ea9ecb9f 100644 --- a/lisp/net/tramp-sh.el +++ b/lisp/net/tramp-sh.el @@ -3647,7 +3647,7 @@ Fall back to normal file name handler if no Tramp handler exists." (set-process-filter p filter) ;; There might be an error if the monitor is not supported. ;; Give the filter a chance to read the output. - (tramp-accept-process-output p 1) + (while (tramp-accept-process-output p)) (unless (process-live-p p) (tramp-error p 'file-notify-error "Monitoring not supported for `%s'" file-name)) diff --git a/lisp/net/tramp-smb.el b/lisp/net/tramp-smb.el index 7163afdcea..a6c95663dd 100644 --- a/lisp/net/tramp-smb.el +++ b/lisp/net/tramp-smb.el @@ -721,7 +721,7 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored." "Read ACL data from connection buffer." (unless (process-live-p proc) ;; Accept pending output. - (while (tramp-accept-process-output proc 0.1)) + (while (tramp-accept-process-output proc)) (with-current-buffer (tramp-get-connection-buffer vec) ;; There might be a hidden password prompt. (widen) @@ -1374,10 +1374,10 @@ component is used as the target of the symlink." (delete-file filename))))) (defun tramp-smb-action-set-acl (proc vec) - "Read ACL data from connection buffer." + "Set ACL data." (unless (process-live-p proc) ;; Accept pending output. - (while (tramp-accept-process-output proc 0.1)) + (while (tramp-accept-process-output proc)) (with-current-buffer (tramp-get-connection-buffer vec) (tramp-message vec 10 "\n%s" (buffer-string)) (throw 'tramp-action 'ok)))) @@ -2043,10 +2043,8 @@ Removes smb prompt. Returns nil if an error message has appeared." (inhibit-read-only t)) ;; Read pending output. - (goto-char (point-min)) - (while (not (or (re-search-forward tramp-smb-prompt nil t) - (re-search-forward tramp-smb-errors nil t))) - (while (tramp-accept-process-output p 0.1) + (while (not (re-search-forward tramp-smb-prompt nil t)) + (while (tramp-accept-process-output p 0) (goto-char (point-min)))) (tramp-message vec 6 "\n%s" (buffer-string)) diff --git a/lisp/net/tramp-sudoedit.el b/lisp/net/tramp-sudoedit.el index ff3a7d7913..6125f6f174 100644 --- a/lisp/net/tramp-sudoedit.el +++ b/lisp/net/tramp-sudoedit.el @@ -747,8 +747,8 @@ ID-FORMAT valid values are `string' and `integer'." "Check, whether a sudo process has finished. Remove unneeded output." ;; There might be pending output for the exit status. - (while (tramp-accept-process-output proc 0.1)) (when (not (process-live-p proc)) + (while (tramp-accept-process-output proc 0)) ;; Delete narrowed region, it would be in the way reading a Lisp form. (goto-char (point-min)) (widen) diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index 3c7770af87..1f018e5cd4 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el @@ -3977,7 +3977,7 @@ The terminal type can be configured with `tramp-terminal-type'." (defun tramp-action-out-of-band (proc vec) "Check, whether an out-of-band copy has finished." ;; There might be pending output for the exit status. - (while (tramp-accept-process-output proc 0.1)) + (while (tramp-accept-process-output proc 0)) (cond ((and (not (process-live-p proc)) (zerop (process-exit-status proc))) (tramp-message vec 3 "Process has finished.") @@ -4007,7 +4007,7 @@ The terminal type can be configured with `tramp-terminal-type'." (while (not found) ;; Reread output once all actions have been performed. ;; Obviously, the output was not complete. - (tramp-accept-process-output proc 1) + (while (tramp-accept-process-output proc 0)) (setq todo actions) (while todo (setq item (pop todo)) @@ -4078,7 +4078,7 @@ connection buffer." ;;; Utility functions: -(defun tramp-accept-process-output (proc timeout) +(defun tramp-accept-process-output (proc &optional timeout) "Like `accept-process-output' for Tramp processes. This is needed in order to hide `last-coding-system-used', which is set for process communication also." @@ -4088,15 +4088,12 @@ for process communication also." ;; We do not want to run timers. timer-list timer-idle-list result) - ;; Under Windows XP, `accept-process-output' doesn't return - ;; sometimes. So we add an additional timeout. JUST-THIS-ONE - ;; is set due to Bug#12145. It is an integer, in order to avoid - ;; running timers as well. + ;; JUST-THIS-ONE is set due to Bug#12145. It is an integer, in + ;; order to avoid running timers. (tramp-message - proc 10 "%s %s %s\n%s" - proc (process-status proc) - (setq result (with-timeout (timeout) - (accept-process-output proc timeout nil 0))) + proc 10 "%s %s %s %s\n%s" + proc timeout (process-status proc) + (setq result (accept-process-output proc timeout nil 0)) (buffer-string)) result))) @@ -4146,14 +4143,14 @@ nil." (cond (timeout (with-timeout (timeout) (while (not found) - (tramp-accept-process-output proc 1) + (tramp-accept-process-output proc) (unless (process-live-p proc) (tramp-error-with-buffer nil proc 'file-error "Process has died")) (setq found (tramp-check-for-regexp proc regexp))))) (t (while (not found) - (tramp-accept-process-output proc 1) + (tramp-accept-process-output proc) (unless (process-live-p proc) (tramp-error-with-buffer nil proc 'file-error "Process has died")) @@ -4831,8 +4828,7 @@ Only works for Bourne-like shells." ;; fall back to the default implementation. (with-timeout (1 (ignore)) ;; We cannot run `tramp-accept-process-output', it blocks timers. - (while (or (accept-process-output proc 0.1) - (process-live-p proc))) + (while (accept-process-output proc nil nil t)) ;; Report success. proc))))) commit cd06d173a602bf0aa8a227ff1626dc70013fe480 Author: Eli Zaretskii Date: Mon Jan 28 17:24:04 2019 +0200 Fix bug with face-id after restoring from pdump * src/xfaces.c (init_xfaces): New function. * src/emacs.c (main) [HAVE_PDUMPER]: If dumped with pdumper, call init_xfaces. (Bug#34226) * src/lisp.h (init_xfaces) [HAVE_PDUMPER]: Add prototype. * test/lisp/faces-tests.el (faces--test-face-id): New test for bug#34226. diff --git a/src/emacs.c b/src/emacs.c index 2acee8e6fe..d6b8a87c72 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -1484,6 +1484,11 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem running_asynch_code = 0; init_random (); +#ifdef HAVE_PDUMPER + if (dumped_with_pdumper_p ()) + init_xfaces (); +#endif + #if defined HAVE_JSON && !defined WINDOWSNT init_json (); #endif diff --git a/src/lisp.h b/src/lisp.h index c5631e2845..5159f050a4 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -4606,6 +4606,9 @@ extern void syms_of_w32cygwinx (void); extern Lisp_Object Vface_alternative_font_family_alist; extern Lisp_Object Vface_alternative_font_registry_alist; extern void syms_of_xfaces (void); +#ifdef HAVE_PDUMPER +extern void init_xfaces (void); +#endif #ifdef HAVE_X_WINDOWS /* Defined in xfns.c. */ diff --git a/src/xfaces.c b/src/xfaces.c index cffa89e1f3..7facb13b76 100644 --- a/src/xfaces.c +++ b/src/xfaces.c @@ -6507,6 +6507,46 @@ DEFUN ("show-face-resources", Fshow_face_resources, Sshow_face_resources, Initialization ***********************************************************************/ +#ifdef HAVE_PDUMPER +/* All the faces defined during loadup are recorded in + face-new-frame-defaults, with the last face first in the list. We + need to set next_lface_id to the next face ID number, so that any + new faces defined in this session will have face IDs different from + those defined during loadup. We also need to set up the + lface_id_to_name[] array for the faces that were defined during + loadup. */ +void +init_xfaces (void) +{ + if (CONSP (Vface_new_frame_defaults)) + { + Lisp_Object lface = XCAR (Vface_new_frame_defaults); + if (CONSP (lface)) + { + /* The first face in the list is the last face defined + during loadup. Compute how many faces are there, and + allocate the lface_id_to_name[] array. */ + Lisp_Object lface_id = Fget (XCAR (lface), Qface); + lface_id_to_name_size = next_lface_id = XFIXNAT (lface_id) + 1; + lface_id_to_name = xnmalloc (next_lface_id, sizeof *lface_id_to_name); + /* Store the last face. */ + lface_id_to_name[next_lface_id - 1] = lface; + + /* Store the rest of the faces. */ + Lisp_Object tail; + for (tail = XCDR (Vface_new_frame_defaults); CONSP (tail); + tail = XCDR (tail)) + { + lface = XCAR (tail); + int face_id = XFIXNAT (Fget (XCAR (lface), Qface)); + eassert (face_id < lface_id_to_name_size); + lface_id_to_name[face_id] = lface; + } + } + } +} +#endif + void syms_of_xfaces (void) { diff --git a/test/lisp/faces-tests.el b/test/lisp/faces-tests.el index 4447dd7b30..f00c93cedc 100644 --- a/test/lisp/faces-tests.el +++ b/test/lisp/faces-tests.el @@ -60,5 +60,14 @@ (should (equal (background-color-at-point) "black")) (should (equal (foreground-color-at-point) "black")))) +(ert-deftest faces--test-face-id () + ;; Face ID of 0 is the 'default' face; no face should have the same ID. + (should (> (face-id 'faces--test1) 0)) + ;; 'tooltip' is the last face defined by preloaded packages, so any + ;; face we define in Emacs should have a face ID greater than that, + ;; since the ID of a face is just its index in the array that maps + ;; face IDs to faces. + (should (> (face-id 'faces--test1) (face-id 'tooltip)))) + (provide 'faces-tests) ;;; faces-tests.el ends here commit fa7a841124578c00872d8a5aa834f6bbe57400ff Author: Sam Steingold Date: Mon Jan 28 09:56:47 2019 -0500 links: also link pdmp diff --git a/nextstep/Makefile.in b/nextstep/Makefile.in index ea64af60ca..4eda9f4e1a 100644 --- a/nextstep/Makefile.in +++ b/nextstep/Makefile.in @@ -85,6 +85,7 @@ links: ../src/emacs${EXEEXT} ln -s $(top_srcdir_abs)/info ${ns_appdir}/Contents/Resources ${MKDIR_P} ${ns_appbindir} ln -s $(abs_top_builddir)/src/emacs${EXEEXT} ${ns_appbindir}/Emacs + ln -s $(abs_top_builddir)/src/emacs${EXEEXT}.pdmp ${ns_appbindir}/ ln -s $(abs_top_builddir)/lib-src ${ns_appbindir}/bin ln -s $(abs_top_builddir)/lib-src ${ns_appbindir}/libexec ${MKDIR_P} ${ns_appdir}/Contents/Resources/etc commit 239386806ec637419786bd1ab21e002bf2d501c1 Author: Alan Mackenzie Date: Mon Jan 28 10:54:42 2019 +0000 Detect when we hit limit in backward search in c-just-after-func-arglist-p This fixes a bug reported by Yasushi SHOJI to emacs-devel on 2018-11-26, where wrong analysis and fontification occurred. * lisp/progmodes/cc-engine.el (c-beginning-of-statement-1): Add new parameter HIT-LIM which, if non-nil causes the function to return nil rather than 'same when we reach the backward search limit without finding the beginning of statement. (c-just-after-func-arglist-p): Supply argument t to this new parameter in call to c-beginning-of-statement-1. diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el index 90e4438ea4..b4c12896f3 100644 --- a/lisp/progmodes/cc-engine.el +++ b/lisp/progmodes/cc-engine.el @@ -665,10 +665,12 @@ comment at the start of cc-engine.el for more info." stack (cdr stack)) t ,do-if-done + (setq pre-stmt-found t) (throw 'loop nil))) (defmacro c-bos-pop-state-and-retry () '(throw 'loop (setq state (car (car stack)) saved-pos (cdr (car stack)) + pre-stmt-found (not (cdr stack)) ;; Throw nil if stack is empty, else throw non-nil. stack (cdr stack)))) (defmacro c-bos-save-pos () @@ -694,7 +696,7 @@ comment at the start of cc-engine.el for more info." (c-point 'bol (elt saved-pos 0)))))))) (defun c-beginning-of-statement-1 (&optional lim ignore-labels - noerror comma-delim) + noerror comma-delim hit-lim) "Move to the start of the current statement or declaration, or to the previous one if already at the beginning of one. Only statements/declarations on the same level are considered, i.e. don't @@ -729,14 +731,16 @@ Return: `up' if stepped to a containing statement; `previous' if stepped to a preceding statement; `beginning' if stepped from a statement continuation clause to - its start clause; or -`macro' if stepped to a macro start. + its start clause; +`macro' if stepped to a macro start; or +nil if HIT-LIM is non-nil, and we hit the limit. Note that `same' and not `label' is returned if stopped at the same label without crossing the colon character. LIM may be given to limit the search. If the search hits the limit, point will be left at the closest following token, or at the start -position if that is less (`same' is returned in this case). +position if that is less. If HIT-LIM is non-nil, nil is returned in +this case, otherwise `same'. NOERROR turns off error logging to `c-parsing-error'. @@ -840,6 +844,10 @@ comment at the start of cc-engine.el for more info." pos ;; Position of last stmt boundary character (e.g. ;). boundary-pos + ;; Non-nil when a construct has been found which delimits the search + ;; for a statement start, e.g. an opening brace or a macro start, or a + ;; keyword like `if' when the PDA stack is empty. + pre-stmt-found ;; The position of the last sexp or bound that follows the ;; first found colon, i.e. the start of the nonlabel part of ;; the statement. It's `start' if a colon is found just after @@ -877,7 +885,10 @@ comment at the start of cc-engine.el for more info." tok ptok pptok) (save-restriction - (if lim (narrow-to-region lim (point-max))) + (setq lim (if lim + (max lim (point-min)) + (point-min))) + (widen) (if (save-excursion (and (c-beginning-of-macro) @@ -923,9 +934,10 @@ comment at the start of cc-engine.el for more info." ;; The loop is exited only by throwing nil to the (catch 'loop ...): ;; 1. On reaching the start of a macro; ;; 2. On having passed a stmt boundary with the PDA stack empty; - ;; 3. On reaching the start of an Objective C method def; - ;; 4. From macro `c-bos-pop-state'; when the stack is empty; - ;; 5. From macro `c-bos-pop-state-and-retry' when the stack is empty. + ;; 3. Going backwards past the search limit. + ;; 4. On reaching the start of an Objective C method def; + ;; 5. From macro `c-bos-pop-state'; when the stack is empty; + ;; 6. From macro `c-bos-pop-state-and-retry' when the stack is empty. (while (catch 'loop ;; Throw nil to break, non-nil to continue. (cond @@ -950,6 +962,7 @@ comment at the start of cc-engine.el for more info." (setq pos saved ret 'macro ignore-labels t)) + (setq pre-stmt-found t) (throw 'loop nil)) ; 1. Start of macro. ;; Do a round through the automaton if we've just passed a @@ -959,6 +972,7 @@ comment at the start of cc-engine.el for more info." (setq sym (intern (match-string 1))))) (when (and (< pos start) (null stack)) + (setq pre-stmt-found t) (throw 'loop nil)) ; 2. Statement boundary. ;; The PDA state handling. @@ -1071,7 +1085,8 @@ comment at the start of cc-engine.el for more info." ;; Step to the previous sexp, but not if we crossed a ;; boundary, since that doesn't consume an sexp. (if (eq sym 'boundary) - (setq ret 'previous) + (when (>= (point) lim) + (setq ret 'previous)) ;; HERE IS THE SINGLE PLACE INSIDE THE PDA LOOP WHERE WE MOVE ;; BACKWARDS THROUGH THE SOURCE. @@ -1093,6 +1108,7 @@ comment at the start of cc-engine.el for more info." ;; Give up if we hit an unbalanced block. Since the ;; stack won't be empty the code below will report a ;; suitable error. + (setq pre-stmt-found t) (throw 'loop nil)) (cond ;; Have we moved into a macro? @@ -1162,12 +1178,17 @@ comment at the start of cc-engine.el for more info." ;; Like a C "continue". Analyze the next sexp. (throw 'loop t)))) + ;; Have we gone past the limit? + (when (< (point) lim) + (throw 'loop nil)) ; 3. Gone back over the limit. + ;; ObjC method def? (when (and c-opt-method-key (setq saved (c-in-method-def-p))) (setq pos saved + pre-stmt-found t ignore-labels t) ; Avoid the label check on exit. - (throw 'loop nil)) ; 3. ObjC method def. + (throw 'loop nil)) ; 4. ObjC method def. ;; Might we have a bitfield declaration, " : "? (if c-has-bitfields @@ -1228,9 +1249,15 @@ comment at the start of cc-engine.el for more info." ptok tok tok (point) pos tok) ; always non-nil - ) ; end of (catch loop ....) + ) ; end of (catch 'loop ....) ) ; end of sexp-at-a-time (while ....) + (when (and hit-lim + (or (not pre-stmt-found) + (< pos lim) + (>= pos start))) + (setq ret nil)) + ;; If the stack isn't empty there might be errors to report. (while stack (if (and (vectorp saved-pos) (eq (length saved-pos) 3)) @@ -9659,7 +9686,7 @@ comment at the start of cc-engine.el for more info." (let ((beg (point)) id-start) (and - (eq (c-beginning-of-statement-1 lim) 'same) + (eq (c-beginning-of-statement-1 lim nil nil nil t) 'same) (not (and (c-major-mode-is 'objc-mode) (c-forward-objc-directive)))