aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2011-01-28 16:11:19 -0500
committerStefan Monnier2011-01-28 16:11:19 -0500
commit07b741a76a67686170d6121790ed36e8d3f8a011 (patch)
tree13ec89da94b099947d223e141a4e482dffe902cb
parent01c63f4ce4a85d3429dc56b72fdb8514dea8874d (diff)
downloademacs-07b741a76a67686170d6121790ed36e8d3f8a011.tar.gz
emacs-07b741a76a67686170d6121790ed36e8d3f8a011.zip
Minor cleanup for compile.el and grep.el.
* lisp/progmodes/compile.el: Cleanup text-properties namespace by using `compilation-message' instead of `message', `compilation-directory' instead of `directory', and `compilation-debug' instead of `debug'. (compilation-last-buffer, compilation-parsing-end) (compilation-error-list, compilation-old-error-list): Move to the compatibility part of the code. (compilation-error-properties): If `file' is a function, let it return a file name. (compilation-mode-font-lock-keywords): Be more conservative with the omake "^ *" pattern prefix, to try and minimize the risk of pathologically slow regexp matching. (compilation-start): Use inhibit-read-only. (compilation--unsetup): New function. (compilation-shell-minor-mode, compilation-minor-mode): Use it. (compilation-filter): Minor tweaks. (compilation-next-error-function): Try and avoid abusing variable names. (compilation--flush-file-structure): New fun. (compilation-fake-loc): Use it for cleaner behavior when file is reused. (debug-ignored-errors): Add "Moved past last ...". (compilation--compat-error-properties) (compilation--compat-parse-errors): Rename by doubling the "-". * lisp/progmodes/grep.el (grep-regexp-alist): Tighten regexp. (grep-mode-font-lock-keywords): Remove regexp that seems like a left-over from before we used compile.el. (grep-mode-font-lock-keywords): Call syntax-ppss-flush-cache when modifying the buffer within with-silent-modifications.
-rw-r--r--lisp/ChangeLog28
-rw-r--r--lisp/progmodes/compile.el237
-rw-r--r--lisp/progmodes/grep.el12
3 files changed, 171 insertions, 106 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 2606b5d62ea..b501c6e78a4 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,33 @@
12011-01-28 Stefan Monnier <monnier@iro.umontreal.ca> 12011-01-28 Stefan Monnier <monnier@iro.umontreal.ca>
2 2
3 * progmodes/grep.el (grep-regexp-alist): Tighten regexp.
4 (grep-mode-font-lock-keywords): Remove regexp that seems like
5 a left-over from before we used compile.el.
6 (grep-mode-font-lock-keywords): Call syntax-ppss-flush-cache when
7 modifying the buffer within with-silent-modifications.
8
9 * progmodes/compile.el: Cleanup text-properties namespace by using
10 `compilation-message' instead of `message', `compilation-directory'
11 instead of `directory', and `compilation-debug' instead of `debug'.
12 (compilation-last-buffer, compilation-parsing-end)
13 (compilation-error-list, compilation-old-error-list): Move to the
14 compatibility part of the code.
15 (compilation-error-properties): If `file' is a function, let it return
16 a file name.
17 (compilation-mode-font-lock-keywords): Be more conservative with the
18 omake "^ *" pattern prefix, to try and minimize the risk of
19 pathologically slow regexp matching.
20 (compilation-start): Use inhibit-read-only.
21 (compilation--unsetup): New function.
22 (compilation-shell-minor-mode, compilation-minor-mode): Use it.
23 (compilation-filter): Minor tweaks.
24 (compilation-next-error-function): Try and avoid abusing variable names.
25 (compilation--flush-file-structure): New fun.
26 (compilation-fake-loc): Use it for cleaner behavior when file is reused.
27 (debug-ignored-errors): Add "Moved past last ...".
28 (compilation--compat-error-properties)
29 (compilation--compat-parse-errors): Rename by doubling the "-".
30
3 Port features from the previous prolog.el to the new one. 31 Port features from the previous prolog.el to the new one.
4 * progmodes/prolog.el (prolog-system): Add GNU and ECLiPSe options. 32 * progmodes/prolog.el (prolog-system): Add GNU and ECLiPSe options.
5 (prolog-program-name, prolog-program-switches, prolog-consult-string) 33 (prolog-program-name, prolog-program-switches, prolog-consult-string)
diff --git a/lisp/progmodes/compile.el b/lisp/progmodes/compile.el
index 588275c6513..4cc319b7858 100644
--- a/lisp/progmodes/compile.el
+++ b/lisp/progmodes/compile.el
@@ -544,10 +544,10 @@ you may also want to change `compilation-page-delimiter'.")
544 (1 font-lock-function-name-face) (3 compilation-line-face nil t)) 544 (1 font-lock-function-name-face) (3 compilation-line-face nil t))
545 (" -\\(?:o[= ]?\\|-\\(?:outfile\\|output\\)[= ]\\)\\(\\S +\\)" . 1) 545 (" -\\(?:o[= ]?\\|-\\(?:outfile\\|output\\)[= ]\\)\\(\\S +\\)" . 1)
546 ("^Compilation \\(finished\\).*" 546 ("^Compilation \\(finished\\).*"
547 (0 '(face nil message nil help-echo nil mouse-face nil) t) 547 (0 '(face nil compilation-message nil help-echo nil mouse-face nil) t)
548 (1 compilation-info-face)) 548 (1 compilation-info-face))
549 ("^Compilation \\(exited abnormally\\|interrupt\\|killed\\|terminated\\|segmentation fault\\)\\(?:.*with code \\([0-9]+\\)\\)?.*" 549 ("^Compilation \\(exited abnormally\\|interrupt\\|killed\\|terminated\\|segmentation fault\\)\\(?:.*with code \\([0-9]+\\)\\)?.*"
550 (0 '(face nil message nil help-echo nil mouse-face nil) t) 550 (0 '(face nil compilation-message nil help-echo nil mouse-face nil) t)
551 (1 compilation-error-face) 551 (1 compilation-error-face)
552 (2 compilation-error-face nil t))) 552 (2 compilation-error-face nil t)))
553 "Additional things to highlight in Compilation mode. 553 "Additional things to highlight in Compilation mode.
@@ -738,11 +738,7 @@ Faces `compilation-error-face', `compilation-warning-face',
738 738
739 739
740;; Used for compatibility with the old compile.el. 740;; Used for compatibility with the old compile.el.
741(defvaralias 'compilation-last-buffer 'next-error-last-buffer)
742(defvar compilation-parsing-end (make-marker))
743(defvar compilation-parse-errors-function nil) 741(defvar compilation-parse-errors-function nil)
744(defvar compilation-error-list nil)
745(defvar compilation-old-error-list nil)
746 742
747(defcustom compilation-auto-jump-to-first-error nil 743(defcustom compilation-auto-jump-to-first-error nil
748 "If non-nil, automatically jump to the first error during compilation." 744 "If non-nil, automatically jump to the first error during compilation."
@@ -809,16 +805,16 @@ from a different message."
809(defun compilation-directory-properties (idx leave) 805(defun compilation-directory-properties (idx leave)
810 (if leave (setq leave (match-end leave))) 806 (if leave (setq leave (match-end leave)))
811 ;; find previous stack, and push onto it, or if `leave' pop it 807 ;; find previous stack, and push onto it, or if `leave' pop it
812 (let ((dir (previous-single-property-change (point) 'directory))) 808 (let ((dir (previous-single-property-change (point) 'compilation-directory)))
813 (setq dir (if dir (or (get-text-property (1- dir) 'directory) 809 (setq dir (if dir (or (get-text-property (1- dir) 'compilation-directory)
814 (get-text-property dir 'directory)))) 810 (get-text-property dir 'compilation-directory))))
815 `(face ,(if leave 811 `(face ,(if leave
816 compilation-leave-directory-face 812 compilation-leave-directory-face
817 compilation-enter-directory-face) 813 compilation-enter-directory-face)
818 directory ,(if leave 814 compilation-directory ,(if leave
819 (or (cdr dir) 815 (or (cdr dir)
820 '(nil)) ; nil only isn't a property-change 816 '(nil)) ; nil only isn't a property-change
821 (cons (match-string-no-properties idx) dir)) 817 (cons (match-string-no-properties idx) dir))
822 mouse-face highlight 818 mouse-face highlight
823 keymap compilation-button-map 819 keymap compilation-button-map
824 help-echo "mouse-2: visit destination directory"))) 820 help-echo "mouse-2: visit destination directory")))
@@ -857,28 +853,29 @@ from a different message."
857;; Return a property list with all meta information on this error location. 853;; Return a property list with all meta information on this error location.
858 854
859(defun compilation-error-properties (file line end-line col end-col type fmt) 855(defun compilation-error-properties (file line end-line col end-col type fmt)
860 (unless (< (next-single-property-change (match-beginning 0) 856 (unless (text-property-not-all (match-beginning 0) (point)
861 'directory nil (point)) 857 'compilation-message nil)
862 (point))
863 (if file 858 (if file
864 (if (functionp file) 859 (when (stringp
865 (setq file (funcall file)) 860 (setq file (if (functionp file) (funcall file)
866 (let (dir) 861 (match-string-no-properties file))))
867 (setq file (match-string-no-properties file)) 862 (let ((dir
868 (unless (file-name-absolute-p file) 863 (unless (file-name-absolute-p file)
869 (setq dir (previous-single-property-change (point) 'directory) 864 (let ((pos (previous-single-property-change
870 dir (if dir (or (get-text-property (1- dir) 'directory) 865 (point) 'compilation-directory)))
871 (get-text-property dir 'directory))))) 866 (when pos
867 (or (get-text-property (1- pos) 'compilation-directory)
868 (get-text-property pos 'compilation-directory)))))))
872 (setq file (cons file (car dir))))) 869 (setq file (cons file (car dir)))))
873 ;; This message didn't mention one, get it from previous 870 ;; This message didn't mention one, get it from previous
874 (let ((prev-pos 871 (let ((prev-pos
875 ;; Find the previous message. 872 ;; Find the previous message.
876 (previous-single-property-change (point) 'message))) 873 (previous-single-property-change (point) 'compilation-message)))
877 (if prev-pos 874 (if prev-pos
878 ;; Get the file structure that belongs to it. 875 ;; Get the file structure that belongs to it.
879 (let* ((prev 876 (let* ((prev
880 (or (get-text-property (1- prev-pos) 'message) 877 (or (get-text-property (1- prev-pos) 'compilation-message)
881 (get-text-property prev-pos 'message))) 878 (get-text-property prev-pos 'compilation-message)))
882 (prev-struct 879 (prev-struct
883 (car (nth 2 (car prev))))) 880 (car (nth 2 (car prev)))))
884 ;; Construct FILE . DIR from that. 881 ;; Construct FILE . DIR from that.
@@ -917,7 +914,8 @@ from a different message."
917 (run-with-timer 0 nil 'compilation-auto-jump 914 (run-with-timer 0 nil 'compilation-auto-jump
918 (current-buffer) (match-beginning 0))) 915 (current-buffer) (match-beginning 0)))
919 916
920 (compilation-internal-error-properties file line end-line col end-col type fmt))) 917 (compilation-internal-error-properties
918 file line end-line col end-col type fmt)))
921 919
922(defun compilation-move-to-column (col screen) 920(defun compilation-move-to-column (col screen)
923 "Go to column COL on the current line. 921 "Go to column COL on the current line.
@@ -991,23 +989,24 @@ FMTS is a list of format specs for transforming the file name.
991 989
992 ;; Must start with face 990 ;; Must start with face
993 `(face ,compilation-message-face 991 `(face ,compilation-message-face
994 message (,loc ,type ,end-loc) 992 compilation-message (,loc ,type ,end-loc)
995 ,@(if compilation-debug 993 ,@(if compilation-debug
996 `(debug (,(assoc (with-no-warnings matcher) font-lock-keywords) 994 `(compilation-debug
997 ,@(match-data)))) 995 (,(assoc (with-no-warnings matcher) font-lock-keywords)
998 help-echo ,(if col 996 ,@(match-data))))
999 "mouse-2: visit this file, line and column" 997 help-echo ,(if col
1000 (if line 998 "mouse-2: visit this file, line and column"
1001 "mouse-2: visit this file and line" 999 (if line
1002 "mouse-2: visit this file")) 1000 "mouse-2: visit this file and line"
1003 keymap compilation-button-map 1001 "mouse-2: visit this file"))
1004 mouse-face highlight))) 1002 keymap compilation-button-map
1003 mouse-face highlight)))
1005 1004
1006(defun compilation-mode-font-lock-keywords () 1005(defun compilation-mode-font-lock-keywords ()
1007 "Return expressions to highlight in Compilation mode." 1006 "Return expressions to highlight in Compilation mode."
1008 (if compilation-parse-errors-function 1007 (if compilation-parse-errors-function
1009 ;; An old package! Try the compatibility code. 1008 ;; An old package! Try the compatibility code.
1010 '((compilation-compat-parse-errors)) 1009 '((compilation--compat-parse-errors))
1011 (append 1010 (append
1012 ;; make directory tracking 1011 ;; make directory tracking
1013 (if compilation-directory-matcher 1012 (if compilation-directory-matcher
@@ -1035,10 +1034,16 @@ FMTS is a list of format specs for transforming the file name.
1035 ;; another solution is to modify (some?) regexps in 1034 ;; another solution is to modify (some?) regexps in
1036 ;; `compilation-error-regexp-alist'. 1035 ;; `compilation-error-regexp-alist'.
1037 ;; note that omake usage is not limited to ocaml and C (for stubs). 1036 ;; note that omake usage is not limited to ocaml and C (for stubs).
1038 (when (and (= ?^ (aref pat 0)) ; anchored: starts with "^" 1037
1039 ;; but does not allow an arbitrary number of leading spaces 1038 ;; FIXME-omake: Doing it here seems wrong, at least it
1040 (not (and (= ? (aref pat 1)) (= ?* (aref pat 2))))) 1039 ;; should depend on whether or not omake's own error
1041 (setq pat (concat "^ *" (substring pat 1)))) 1040 ;; messages are recognized.
1041 (cond
1042 ((not (memq 'omake compilation-error-regexp-alist)) nil)
1043 ((string-match "\\`\\([^^]\\|^\\( \\*\\|\\[\\)\\)" pat)
1044 nil) ;; Not anchored or anchored but already allows empty spaces.
1045 (t (setq pat (concat "^ *" (substring pat 1)))))
1046
1042 (if (consp file) (setq fmt (cdr file) file (car file))) 1047 (if (consp file) (setq fmt (cdr file) file (car file)))
1043 (if (consp line) (setq end-line (cdr line) line (car line))) 1048 (if (consp line) (setq end-line (cdr line) line (car line)))
1044 (if (consp col) (setq end-col (cdr col) col (car col))) 1049 (if (consp col) (setq end-col (cdr col) col (car col)))
@@ -1049,7 +1054,7 @@ FMTS is a list of format specs for transforming the file name.
1049 ;; error location. Let's do our best. 1054 ;; error location. Let's do our best.
1050 `(,pat 1055 `(,pat
1051 (0 (save-match-data 1056 (0 (save-match-data
1052 (compilation-compat-error-properties 1057 (compilation--compat-error-properties
1053 (funcall ',line (cons (match-string ,file) 1058 (funcall ',line (cons (match-string ,file)
1054 (cons default-directory 1059 (cons default-directory
1055 ',(nthcdr 4 item))) 1060 ',(nthcdr 4 item)))
@@ -1383,7 +1388,7 @@ Returns the compilation buffer created."
1383 ;; Insert the output at the end, after the initial text, 1388 ;; Insert the output at the end, after the initial text,
1384 ;; regardless of where the user sees point. 1389 ;; regardless of where the user sees point.
1385 (goto-char (point-max)) 1390 (goto-char (point-max))
1386 (let* ((buffer-read-only nil) ; call-process needs to modify outbuf 1391 (let* ((inhibit-read-only t) ; call-process needs to modify outbuf
1387 (status (call-process shell-file-name nil outbuf nil "-c" 1392 (status (call-process shell-file-name nil outbuf nil "-c"
1388 command))) 1393 command)))
1389 (cond ((numberp status) 1394 (cond ((numberp status)
@@ -1632,6 +1637,7 @@ by replacing the first word, e.g `compilation-scroll-output' from
1632 (symbol-name v))))) 1637 (symbol-name v)))))
1633 (and (cdr v) 1638 (and (cdr v)
1634 (or (boundp (cdr v)) 1639 (or (boundp (cdr v))
1640 ;; FIXME: This is hackish, using undocumented info.
1635 (if (boundp 'byte-compile-bound-variables) 1641 (if (boundp 'byte-compile-bound-variables)
1636 (memq (cdr v) byte-compile-bound-variables))) 1642 (memq (cdr v) byte-compile-bound-variables)))
1637 `(set (make-local-variable ',(car v)) ,(cdr v)))) 1643 `(set (make-local-variable ',(car v)) ,(cdr v))))
@@ -1691,7 +1697,8 @@ Optional argument MINOR indicates this is called from
1691 (set (make-local-variable 'comint-file-name-prefix) 1697 (set (make-local-variable 'comint-file-name-prefix)
1692 (or (file-remote-p default-directory) "")) 1698 (or (file-remote-p default-directory) ""))
1693 (set (make-local-variable 'font-lock-extra-managed-props) 1699 (set (make-local-variable 'font-lock-extra-managed-props)
1694 '(directory message help-echo mouse-face debug)) 1700 '(compilation-directory compilation-message help-echo mouse-face
1701 compilation-debug))
1695 (set (make-local-variable 'compilation-locs) 1702 (set (make-local-variable 'compilation-locs)
1696 (make-hash-table :test 'equal :weakness 'value)) 1703 (make-hash-table :test 'equal :weakness 'value))
1697 ;; lazy-lock would never find the message unless it's scrolled to. 1704 ;; lazy-lock would never find the message unless it's scrolled to.
@@ -1711,6 +1718,12 @@ Optional argument MINOR indicates this is called from
1711 ;; maybe defer font-lock till after derived mode is set up 1718 ;; maybe defer font-lock till after derived mode is set up
1712 (run-mode-hooks 'compilation-turn-on-font-lock))) 1719 (run-mode-hooks 'compilation-turn-on-font-lock)))
1713 1720
1721(defun compilation--unsetup ()
1722 ;; Only for minor mode.
1723 (font-lock-remove-keywords nil (compilation-mode-font-lock-keywords))
1724 (if font-lock-mode
1725 (font-lock-fontify-buffer)))
1726
1714;;;###autoload 1727;;;###autoload
1715(define-minor-mode compilation-shell-minor-mode 1728(define-minor-mode compilation-shell-minor-mode
1716 "Toggle compilation shell minor mode. 1729 "Toggle compilation shell minor mode.
@@ -1723,8 +1736,7 @@ Turning the mode on runs the normal hook `compilation-shell-minor-mode-hook'."
1723 :group 'compilation 1736 :group 'compilation
1724 (if compilation-shell-minor-mode 1737 (if compilation-shell-minor-mode
1725 (compilation-setup t) 1738 (compilation-setup t)
1726 (font-lock-remove-keywords nil (compilation-mode-font-lock-keywords)) 1739 (compilation--unsetup)))
1727 (font-lock-fontify-buffer)))
1728 1740
1729;;;###autoload 1741;;;###autoload
1730(define-minor-mode compilation-minor-mode 1742(define-minor-mode compilation-minor-mode
@@ -1737,8 +1749,7 @@ Turning the mode on runs the normal hook `compilation-minor-mode-hook'."
1737 :group 'compilation 1749 :group 'compilation
1738 (if compilation-minor-mode 1750 (if compilation-minor-mode
1739 (compilation-setup t) 1751 (compilation-setup t)
1740 (font-lock-remove-keywords nil (compilation-mode-font-lock-keywords)) 1752 (compilation--unsetup)))
1741 (font-lock-fontify-buffer)))
1742 1753
1743(defun compilation-handle-exit (process-status exit-status msg) 1754(defun compilation-handle-exit (process-status exit-status msg)
1744 "Write MSG in the current buffer and hack its `mode-line-process'." 1755 "Write MSG in the current buffer and hack its `mode-line-process'."
@@ -1766,7 +1777,8 @@ Turning the mode on runs the normal hook `compilation-minor-mode-hook'."
1766 (setq mode-line-process 1777 (setq mode-line-process
1767 (let ((out-string (format ":%s [%s]" process-status (cdr status))) 1778 (let ((out-string (format ":%s [%s]" process-status (cdr status)))
1768 (msg (format "%s %s" mode-name 1779 (msg (format "%s %s" mode-name
1769 (replace-regexp-in-string "\n?$" "" (car status))))) 1780 (replace-regexp-in-string "\n?$" ""
1781 (car status)))))
1770 (message "%s" msg) 1782 (message "%s" msg)
1771 (propertize out-string 1783 (propertize out-string
1772 'help-echo msg 'face (if (> exit-status 0) 1784 'help-echo msg 'face (if (> exit-status 0)
@@ -1811,13 +1823,13 @@ and runs `compilation-filter-hook'."
1811 (let ((inhibit-read-only t) 1823 (let ((inhibit-read-only t)
1812 ;; `save-excursion' doesn't use the right insertion-type for us. 1824 ;; `save-excursion' doesn't use the right insertion-type for us.
1813 (pos (copy-marker (point) t)) 1825 (pos (copy-marker (point) t))
1826 ;; `save-restriction' doesn't use the right insertion type either:
1827 ;; If we are inserting at the end of the accessible part of the
1828 ;; buffer, keep the inserted text visible.
1814 (min (point-min-marker)) 1829 (min (point-min-marker))
1815 (max (point-max-marker))) 1830 (max (copy-marker (point-max) t)))
1816 (unwind-protect 1831 (unwind-protect
1817 (progn 1832 (progn
1818 ;; If we are inserting at the end of the accessible part
1819 ;; of the buffer, keep the inserted text visible.
1820 (set-marker-insertion-type max t)
1821 (widen) 1833 (widen)
1822 (goto-char (process-mark proc)) 1834 (goto-char (process-mark proc))
1823 ;; We used to use `insert-before-markers', so that windows with 1835 ;; We used to use `insert-before-markers', so that windows with
@@ -1831,6 +1843,7 @@ and runs `compilation-filter-hook'."
1831 (run-hooks 'compilation-filter-hook)) 1843 (run-hooks 'compilation-filter-hook))
1832 (goto-char pos) 1844 (goto-char pos)
1833 (narrow-to-region min max) 1845 (narrow-to-region min max)
1846 (set-marker pos nil)
1834 (set-marker min nil) 1847 (set-marker min nil)
1835 (set-marker max nil)))))) 1848 (set-marker max nil))))))
1836 1849
@@ -1849,19 +1862,19 @@ and runs `compilation-filter-hook'."
1849 `(let (opt) 1862 `(let (opt)
1850 (while (,< n 0) 1863 (while (,< n 0)
1851 (setq opt pt) 1864 (setq opt pt)
1852 (or (setq pt (,property-change pt 'message)) 1865 (or (setq pt (,property-change pt 'compilation-message))
1853 ;; Handle the case where where the first error message is 1866 ;; Handle the case where where the first error message is
1854 ;; at the start of the buffer, and n < 0. 1867 ;; at the start of the buffer, and n < 0.
1855 (if (or (eq (get-text-property ,limit 'message) 1868 (if (or (eq (get-text-property ,limit 'compilation-message)
1856 (get-text-property opt 'message)) 1869 (get-text-property opt 'compilation-message))
1857 (eq pt opt)) 1870 (eq pt opt))
1858 (error ,error compilation-error) 1871 (error ,error compilation-error)
1859 (setq pt ,limit))) 1872 (setq pt ,limit)))
1860 ;; prop 'message usually has 2 changes, on and off, so 1873 ;; prop 'compilation-message usually has 2 changes, on and off, so
1861 ;; re-search if off 1874 ;; re-search if off
1862 (or (setq msg (get-text-property pt 'message)) 1875 (or (setq msg (get-text-property pt 'compilation-message))
1863 (if (setq pt (,property-change pt 'message nil ,limit)) 1876 (if (setq pt (,property-change pt 'compilation-message nil ,limit))
1864 (setq msg (get-text-property pt 'message))) 1877 (setq msg (get-text-property pt 'compilation-message)))
1865 (error ,error compilation-error)) 1878 (error ,error compilation-error))
1866 (or (< (cadr msg) compilation-skip-threshold) 1879 (or (< (cadr msg) compilation-skip-threshold)
1867 (if different-file 1880 (if different-file
@@ -1887,20 +1900,21 @@ looking for the next message."
1887 (or (compilation-buffer-p (current-buffer)) 1900 (or (compilation-buffer-p (current-buffer))
1888 (error "Not in a compilation buffer")) 1901 (error "Not in a compilation buffer"))
1889 (or pt (setq pt (point))) 1902 (or pt (setq pt (point)))
1890 (let* ((msg (get-text-property pt 'message)) 1903 (let* ((msg (get-text-property pt 'compilation-message))
1891 ;; `loc' is used by the compilation-loop macro. 1904 ;; `loc' is used by the compilation-loop macro.
1892 (loc (car msg)) 1905 (loc (car msg))
1893 last) 1906 last)
1894 (if (zerop n) 1907 (if (zerop n)
1895 (unless (or msg ; find message near here 1908 (unless (or msg ; find message near here
1896 (setq msg (get-text-property (max (1- pt) (point-min)) 1909 (setq msg (get-text-property (max (1- pt) (point-min))
1897 'message))) 1910 'compilation-message)))
1898 (setq pt (previous-single-property-change pt 'message nil 1911 (setq pt (previous-single-property-change pt 'compilation-message nil
1899 (line-beginning-position))) 1912 (line-beginning-position)))
1900 (unless (setq msg (get-text-property (max (1- pt) (point-min)) 'message)) 1913 (unless (setq msg (get-text-property (max (1- pt) (point-min))
1901 (setq pt (next-single-property-change pt 'message nil 1914 'compilation-message))
1915 (setq pt (next-single-property-change pt 'compilation-message nil
1902 (line-end-position))) 1916 (line-end-position)))
1903 (or (setq msg (get-text-property pt 'message)) 1917 (or (setq msg (get-text-property pt 'compilation-message))
1904 (setq pt (point))))) 1918 (setq pt (point)))))
1905 (setq last (nth 2 (car msg))) 1919 (setq last (nth 2 (car msg)))
1906 (if (>= n 0) 1920 (if (>= n 0)
@@ -1911,7 +1925,8 @@ looking for the next message."
1911 (point-max)) 1925 (point-max))
1912 ;; Don't move "back" to message at or before point. 1926 ;; Don't move "back" to message at or before point.
1913 ;; Pass an explicit (point-min) to make sure pt is non-nil. 1927 ;; Pass an explicit (point-min) to make sure pt is non-nil.
1914 (setq pt (previous-single-property-change pt 'message nil (point-min))) 1928 (setq pt (previous-single-property-change
1929 pt 'compilation-message nil (point-min)))
1915 (compilation-loop < previous-single-property-change 1+ 1930 (compilation-loop < previous-single-property-change 1+
1916 "Moved back before first %s" (point-min)))) 1931 "Moved back before first %s" (point-min))))
1917 (goto-char pt) 1932 (goto-char pt)
@@ -1955,12 +1970,15 @@ Use this command in a compilation log buffer. Sets the mark at point there."
1955 (if event (posn-set-point (event-end event))) 1970 (if event (posn-set-point (event-end event)))
1956 (or (compilation-buffer-p (current-buffer)) 1971 (or (compilation-buffer-p (current-buffer))
1957 (error "Not in a compilation buffer")) 1972 (error "Not in a compilation buffer"))
1958 (if (get-text-property (point) 'directory) 1973 (if (get-text-property (point) 'compilation-directory)
1959 (dired-other-window (car (get-text-property (point) 'directory))) 1974 (dired-other-window
1975 (car (get-text-property (point) 'compilation-directory)))
1960 (push-mark) 1976 (push-mark)
1961 (setq compilation-current-error (point)) 1977 (setq compilation-current-error (point))
1962 (next-error-internal))) 1978 (next-error-internal)))
1963 1979
1980;; This is mostly unused, but we keep it for the sake of some external
1981;; packages which seem to make use of it.
1964(defun compilation-find-buffer (&optional avoid-current) 1982(defun compilation-find-buffer (&optional avoid-current)
1965 "Return a compilation buffer. 1983 "Return a compilation buffer.
1966If AVOID-CURRENT is nil, and the current buffer is a compilation buffer, 1984If AVOID-CURRENT is nil, and the current buffer is a compilation buffer,
@@ -1979,18 +1997,18 @@ This is the value of `next-error-function' in Compilation buffers."
1979 (setq compilation-current-error nil)) 1997 (setq compilation-current-error nil))
1980 (let* ((columns compilation-error-screen-columns) ; buffer's local value 1998 (let* ((columns compilation-error-screen-columns) ; buffer's local value
1981 (last 1) timestamp 1999 (last 1) timestamp
1982 (loc (compilation-next-error (or n 1) nil 2000 (msg (compilation-next-error (or n 1) nil
1983 (or compilation-current-error 2001 (or compilation-current-error
1984 compilation-messages-start 2002 compilation-messages-start
1985 (point-min)))) 2003 (point-min))))
1986 (end-loc (nth 2 loc)) 2004 (loc (car msg))
2005 (end-loc (nth 2 msg))
1987 (marker (point-marker))) 2006 (marker (point-marker)))
1988 (setq compilation-current-error (point-marker) 2007 (setq compilation-current-error (point-marker)
1989 overlay-arrow-position 2008 overlay-arrow-position
1990 (if (bolp) 2009 (if (bolp)
1991 compilation-current-error 2010 compilation-current-error
1992 (copy-marker (line-beginning-position))) 2011 (copy-marker (line-beginning-position))))
1993 loc (car loc))
1994 ;; If loc contains no marker, no error in that file has been visited. 2012 ;; If loc contains no marker, no error in that file has been visited.
1995 ;; If the marker is invalid the buffer has been killed. 2013 ;; If the marker is invalid the buffer has been killed.
1996 ;; If the file is newer than the timestamp, it has been modified 2014 ;; If the file is newer than the timestamp, it has been modified
@@ -2036,8 +2054,8 @@ This is the value of `next-error-function' in Compilation buffers."
2036FILE should be ABSOLUTE-FILENAME or (RELATIVE-FILENAME . DIRNAME). 2054FILE should be ABSOLUTE-FILENAME or (RELATIVE-FILENAME . DIRNAME).
2037This is useful when you compile temporary files, but want 2055This is useful when you compile temporary files, but want
2038automatic translation of the messages to the real buffer from 2056automatic translation of the messages to the real buffer from
2039which the temporary file came. This only works if done before a 2057which the temporary file came. This may also affect previous messages
2040message about FILE appears! 2058about FILE.
2041 2059
2042Optional args LINE and COL default to 1 and beginning of 2060Optional args LINE and COL default to 1 and beginning of
2043indentation respectively. The marker is expected to reflect 2061indentation respectively. The marker is expected to reflect
@@ -2049,18 +2067,20 @@ header with variable assignments and a code region), you must
2049call this several times, once each for the last line of one 2067call this several times, once each for the last line of one
2050region and the first line of the next region." 2068region and the first line of the next region."
2051 (or (consp file) (setq file (list file))) 2069 (or (consp file) (setq file (list file)))
2052 (setq file (compilation-get-file-structure file)) 2070 (compilation--flush-file-structure file)
2053 ;; Between the current call to compilation-fake-loc and the first occurrence 2071 (let ((fs (compilation-get-file-structure file)))
2054 ;; of an error message referring to `file', the data is only kept in the 2072 ;; Between the current call to compilation-fake-loc and the first
2055 ;; weak hash-table compilation-locs, so we need to prevent this entry 2073 ;; occurrence of an error message referring to `file', the data is
2056 ;; in compilation-locs from being GC'd away. --Stef 2074 ;; only kept in the weak hash-table compilation-locs, so we need
2057 (push file compilation-gcpro) 2075 ;; to prevent this entry in compilation-locs from being GC'd
2058 (let ((loc (compilation-assq (or line 1) (cdr file)))) 2076 ;; away. --Stef
2059 (setq loc (compilation-assq col loc)) 2077 (push fs compilation-gcpro)
2060 (if (cdr loc) 2078 (let ((loc (compilation-assq (or line 1) (cdr fs))))
2061 (setcdr (cddr loc) (list marker)) 2079 (setq loc (compilation-assq col loc))
2062 (setcdr loc (list line file marker))) 2080 (if (cdr loc)
2063 loc)) 2081 (setcdr (cddr loc) (list marker))
2082 (setcdr loc (list line fs marker)))
2083 loc)))
2064 2084
2065(defcustom compilation-context-lines nil 2085(defcustom compilation-context-lines nil
2066 "Display this many lines of leading context before the current message. 2086 "Display this many lines of leading context before the current message.
@@ -2278,7 +2298,7 @@ FILE should be (FILENAME) or (RELATIVE-FILENAME . DIRNAME).
2278In the former case, FILENAME may be relative or absolute. 2298In the former case, FILENAME may be relative or absolute.
2279 2299
2280The file-structure looks like this: 2300The file-structure looks like this:
2281 (list (list FILENAME [DIR-FROM-PREV-MSG]) FMT LINE-STRUCT...)" 2301 ((FILENAME [DIR-FROM-PREV-MSG]) FMT LINE-STRUCT...)"
2282 (or (gethash file compilation-locs) 2302 (or (gethash file compilation-locs)
2283 ;; File was not previously encountered, at least not in the form passed. 2303 ;; File was not previously encountered, at least not in the form passed.
2284 ;; Let's normalize it and look again. 2304 ;; Let's normalize it and look again.
@@ -2327,13 +2347,27 @@ The file-structure looks like this:
2327 compilation-locs)) 2347 compilation-locs))
2328 compilation-locs)))) 2348 compilation-locs))))
2329 2349
2330(add-to-list 'debug-ignored-errors "^No more [-a-z ]+s yet$") 2350(defun compilation--flush-file-structure (file)
2351 (or (consp file) (setq file (list file)))
2352 (let ((fs (compilation-get-file-structure file)))
2353 (assert (eq fs (gethash file compilation-locs)))
2354 (assert (eq fs (gethash (cons (caar fs) (cadr (car fs)))
2355 compilation-locs)))
2356 (maphash (lambda (k v)
2357 (if (eq v fs) (remhash k compilation-locs)))
2358 compilation-locs)))
2359
2360(add-to-list 'debug-ignored-errors "\\`No more [-a-z ]+s yet\\'")
2361(add-to-list 'debug-ignored-errors "\\`Moved past last .*")
2331 2362
2332;;; Compatibility with the old compile.el. 2363;;; Compatibility with the old compile.el.
2333 2364
2334(defun compile-buffer-substring (n) (if n (match-string n))) 2365(defvaralias 'compilation-last-buffer 'next-error-last-buffer)
2366(defvar compilation-parsing-end (make-marker))
2367(defvar compilation-error-list nil)
2368(defvar compilation-old-error-list nil)
2335 2369
2336(defun compilation-compat-error-properties (err) 2370(defun compilation--compat-error-properties (err)
2337 "Map old-style error ERR to new-style message." 2371 "Map old-style error ERR to new-style message."
2338 ;; Old-style structure is (MARKER (FILE DIR) LINE COL) or 2372 ;; Old-style structure is (MARKER (FILE DIR) LINE COL) or
2339 ;; (MARKER . MARKER). 2373 ;; (MARKER . MARKER).
@@ -2341,7 +2375,7 @@ The file-structure looks like this:
2341 (if (markerp dst) 2375 (if (markerp dst)
2342 ;; Must start with a face, for font-lock. 2376 ;; Must start with a face, for font-lock.
2343 `(face nil 2377 `(face nil
2344 message ,(list (list nil nil nil dst) 2) 2378 compilation-message ,(list (list nil nil nil dst) 2)
2345 help-echo "mouse-2: visit the source location" 2379 help-echo "mouse-2: visit the source location"
2346 keymap compilation-button-map 2380 keymap compilation-button-map
2347 mouse-face highlight) 2381 mouse-face highlight)
@@ -2355,19 +2389,19 @@ The file-structure looks like this:
2355 (compilation-internal-error-properties 2389 (compilation-internal-error-properties
2356 (cons filename dirname) line nil col nil 2 fmt))))) 2390 (cons filename dirname) line nil col nil 2 fmt)))))
2357 2391
2358(defun compilation-compat-parse-errors (limit) 2392(defun compilation--compat-parse-errors (limit)
2359 (when compilation-parse-errors-function 2393 (when compilation-parse-errors-function
2360 ;; FIXME: We should remove the rest of the compilation keywords 2394 ;; FIXME: We should remove the rest of the compilation keywords
2361 ;; but we can't do that from here because font-lock is using 2395 ;; but we can't do that from here because font-lock is using
2362 ;; the value right now. --stef 2396 ;; the value right now. --Stef
2363 (save-excursion 2397 (save-excursion
2364 (setq compilation-error-list nil) 2398 (setq compilation-error-list nil)
2365 ;; Reset compilation-parsing-end each time because font-lock 2399 ;; Reset compilation-parsing-end each time because font-lock
2366 ;; might force us the re-parse many times (typically because 2400 ;; might force us the re-parse many times (typically because
2367 ;; some code adds some text-property to the output that we 2401 ;; some code adds some text-property to the output that we
2368 ;; already parsed). You might say "why reparse", well: 2402 ;; already parsed). You might say "why reparse", well:
2369 ;; because font-lock has just removed the `message' property so 2403 ;; because font-lock has just removed the `compilation-message' property
2370 ;; have to do it all over again. 2404 ;; so have to do it all over again.
2371 (if compilation-parsing-end 2405 (if compilation-parsing-end
2372 (set-marker compilation-parsing-end (point)) 2406 (set-marker compilation-parsing-end (point))
2373 (setq compilation-parsing-end (point-marker))) 2407 (setq compilation-parsing-end (point-marker)))
@@ -2385,13 +2419,14 @@ The file-structure looks like this:
2385 (cons (cdar dst) (caar dst))))))) 2419 (cons (cdar dst) (caar dst)))))))
2386 (when loc 2420 (when loc
2387 (goto-char src) 2421 (goto-char src)
2388 ;; (put-text-property src (line-end-position) 'font-lock-face 'font-lock-warning-face) 2422 ;; (put-text-property src (line-end-position)
2423 ;; 'font-lock-face 'font-lock-warning-face)
2389 (put-text-property src (line-end-position) 2424 (put-text-property src (line-end-position)
2390 'message (list loc 2))))))) 2425 'compilation-message (list loc 2)))))))
2391 (goto-char limit) 2426 (goto-char limit)
2392 nil) 2427 nil)
2393 2428
2394;; Beware: this is not only compatibility code. New code stil uses it. --Stef 2429;; Beware! this is not only compatibility code. New code also uses it. --Stef
2395(defun compilation-forget-errors () 2430(defun compilation-forget-errors ()
2396 ;; In case we hit the same file/line specs, we want to recompute a new 2431 ;; In case we hit the same file/line specs, we want to recompute a new
2397 ;; marker for them, so flush our cache. 2432 ;; marker for them, so flush our cache.
diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el
index ff943e654ab..4bab8a18dee 100644
--- a/lisp/progmodes/grep.el
+++ b/lisp/progmodes/grep.el
@@ -341,7 +341,7 @@ Notice that using \\[next-error] or \\[compile-goto-error] modifies
341 341
342;;;###autoload 342;;;###autoload
343(defconst grep-regexp-alist 343(defconst grep-regexp-alist
344 '(("^\\(.+?\\)\\(:[ \t]*\\)\\([0-9]+\\)\\2" 344 '(("^\\(.+?\\)\\(:[ \t]*\\)\\([1-9][0-9]*\\)\\2"
345 1 3) 345 1 3)
346 ;; Rule to match column numbers is commented out since no known grep 346 ;; Rule to match column numbers is commented out since no known grep
347 ;; produces them 347 ;; produces them
@@ -384,7 +384,6 @@ Notice that using \\[next-error] or \\[compile-goto-error] modifies
384 384
385(defvar grep-mode-font-lock-keywords 385(defvar grep-mode-font-lock-keywords
386 '(;; Command output lines. 386 '(;; Command output lines.
387 ("^\\([A-Za-z_0-9/\.+-]+\\)[ \t]*:" 1 font-lock-function-name-face)
388 (": \\(.+\\): \\(?:Permission denied\\|No such \\(?:file or directory\\|device or address\\)\\)$" 387 (": \\(.+\\): \\(?:Permission denied\\|No such \\(?:file or directory\\|device or address\\)\\)$"
389 1 grep-error-face) 388 1 grep-error-face)
390 ;; remove match from grep-regexp-alist before fontifying 389 ;; remove match from grep-regexp-alist before fontifying
@@ -399,7 +398,8 @@ Notice that using \\[next-error] or \\[compile-goto-error] modifies
399 (1 grep-error-face) 398 (1 grep-error-face)
400 (2 grep-error-face nil t)) 399 (2 grep-error-face nil t))
401 ("^.+?-[0-9]+-.*\n" (0 grep-context-face)) 400 ("^.+?-[0-9]+-.*\n" (0 grep-context-face))
402 ;; Highlight grep matches and delete markers 401 ;; Highlight grep matches and delete markers.
402 ;; FIXME: Modifying the buffer text from font-lock is a bad idea!
403 ("\\(\033\\[01;31m\\)\\(.*?\\)\\(\033\\[[0-9]*m\\)" 403 ("\\(\033\\[01;31m\\)\\(.*?\\)\\(\033\\[[0-9]*m\\)"
404 ;; Refontification does not work after the markers have been 404 ;; Refontification does not work after the markers have been
405 ;; deleted. So we use the font-lock-face property here as Font 405 ;; deleted. So we use the font-lock-face property here as Font
@@ -409,12 +409,14 @@ Notice that using \\[next-error] or \\[compile-goto-error] modifies
409 (progn 409 (progn
410 ;; Delete markers with `replace-match' because it updates 410 ;; Delete markers with `replace-match' because it updates
411 ;; the match-data, whereas `delete-region' would render it obsolete. 411 ;; the match-data, whereas `delete-region' would render it obsolete.
412 (syntax-ppss-flush-cache (match-beginning 0))
412 (replace-match "" t t nil 3) 413 (replace-match "" t t nil 3)
413 (replace-match "" t t nil 1)))) 414 (replace-match "" t t nil 1))))
414 ("\\(\033\\[[0-9;]*[mK]\\)" 415 ("\033\\[[0-9;]*[mK]"
415 ;; Delete all remaining escape sequences 416 ;; Delete all remaining escape sequences
416 ((lambda (bound)) 417 ((lambda (bound))
417 (replace-match "" t t nil 1)))) 418 (syntax-ppss-flush-cache (match-beginning 0))
419 (replace-match "" t t))))
418 "Additional things to highlight in grep output. 420 "Additional things to highlight in grep output.
419This gets tacked on the end of the generated expressions.") 421This gets tacked on the end of the generated expressions.")
420 422