aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2002-11-07 19:16:15 +0000
committerStefan Monnier2002-11-07 19:16:15 +0000
commit4282eba157a62c7b9710bc41a72668dab4ea0981 (patch)
tree9f7bf664863be4c31610433ab903950bc3d80617
parent07daadbd3233bbdcf59a710d01ad58b034335d21 (diff)
downloademacs-4282eba157a62c7b9710bc41a72668dab4ea0981.tar.gz
emacs-4282eba157a62c7b9710bc41a72668dab4ea0981.zip
(grep-default-command): New fun.
(grep): Use it. (compilation-menu-map): New var. (compilation-minor-mode-map, compilation-shell-minor-mode-map): Use it. (compilation-mode-map): Simplify. (compilation-shell-minor-mode, compilation-minor-mode): Use define-minor-mode.
-rw-r--r--lisp/progmodes/compile.el174
1 files changed, 77 insertions, 97 deletions
diff --git a/lisp/progmodes/compile.el b/lisp/progmodes/compile.el
index 6cfb06ad2f1..4c727cdfd19 100644
--- a/lisp/progmodes/compile.el
+++ b/lisp/progmodes/compile.el
@@ -748,6 +748,36 @@ original use. Otherwise, it recompiles using `compile-command'."
748 (t (format "%s <D> <X> -type f <F> -exec %s <R> {} %s \\;" 748 (t (format "%s <D> <X> -type f <F> -exec %s <R> {} %s \\;"
749 find-program gcmd null-device))))))) 749 find-program gcmd null-device)))))))
750 750
751(defun grep-default-command ()
752 (let ((tag-default
753 (funcall (or find-tag-default-function
754 (get major-mode 'find-tag-default-function)
755 ;; We use grep-tag-default instead of
756 ;; find-tag-default, to avoid loading etags.
757 'grep-tag-default)))
758 (sh-arg-re "\\(\\(?:\"\\(?:[^\"]\\|\\\\\"\\)+\"\\|'[^']+'\\|[^\"' \t\n]\\)+\\)")
759 (grep-default (or (car grep-history) grep-command)))
760 ;; Replace the thing matching for with that around cursor.
761 (when (or (string-match
762 (concat "[^ ]+\\s +\\(?:-[^ ]+\\s +\\)*"
763 sh-arg-re "\\(\\s +\\(\\S +\\)\\)?")
764 grep-default)
765 ;; If the string is not yet complete.
766 (string-match "\\(\\)\\'" grep-default))
767 (unless (or (not (stringp buffer-file-name))
768 (when (match-beginning 2)
769 (save-match-data
770 (string-match
771 (wildcard-to-regexp
772 (file-name-nondirectory
773 (match-string 3 grep-default)))
774 (file-name-nondirectory buffer-file-name)))))
775 (setq grep-default (concat (substring grep-default
776 0 (match-beginning 2))
777 " *."
778 (file-name-extension buffer-file-name))))
779 (replace-match (or tag-default "") t t grep-default 1))))
780
751;;;###autoload 781;;;###autoload
752(defun grep (command-args) 782(defun grep (command-args)
753 "Run grep, with user-specified args, and collect output in a buffer. 783 "Run grep, with user-specified args, and collect output in a buffer.
@@ -764,28 +794,16 @@ tag the cursor is over, substituting it into the last grep command
764in the grep command history (or into `grep-command' 794in the grep command history (or into `grep-command'
765if that history list is empty)." 795if that history list is empty)."
766 (interactive 796 (interactive
767 (let (grep-default (arg current-prefix-arg)) 797 (progn
768 (unless (and grep-command 798 (unless (and grep-command
769 (or (not grep-use-null-device) (eq grep-use-null-device t))) 799 (or (not grep-use-null-device) (eq grep-use-null-device t)))
770 (grep-compute-defaults)) 800 (grep-compute-defaults))
771 (when arg 801 (let ((default (grep-default-command)))
772 (let ((tag-default 802 (list (read-from-minibuffer "Run grep (like this): "
773 (funcall (or find-tag-default-function 803 (if current-prefix-arg
774 (get major-mode 'find-tag-default-function) 804 default grep-command)
775 ;; We use grep-tag-default instead of 805 nil nil 'grep-history
776 ;; find-tag-default, to avoid loading etags. 806 (if current-prefix-arg nil default))))))
777 'grep-tag-default))))
778 (setq grep-default (or (car grep-history) grep-command))
779 ;; Replace the thing matching for with that around cursor
780 (when (string-match "[^ ]+\\s +\\(-[^ ]+\\s +\\)*\\(\"[^\"]+\"\\|[^ ]+\\)\\(\\s-+\\S-+\\)?" grep-default)
781 (unless (or (match-beginning 3) (not (stringp buffer-file-name)))
782 (setq grep-default (concat grep-default "*."
783 (file-name-extension buffer-file-name))))
784 (setq grep-default (replace-match (or tag-default "")
785 t t grep-default 2)))))
786 (list (read-from-minibuffer "Run grep (like this): "
787 (or grep-default grep-command)
788 nil nil 'grep-history))))
789 807
790 ;; Setting process-setup-function makes exit-message-function work 808 ;; Setting process-setup-function makes exit-message-function work
791 ;; even when async processes aren't supported. 809 ;; even when async processes aren't supported.
@@ -1136,6 +1154,20 @@ exited abnormally with code %d\n"
1136 (when (window-live-p w) 1154 (when (window-live-p w)
1137 (select-window w))))))) 1155 (select-window w)))))))
1138 1156
1157(defvar compilation-menu-map
1158 (let ((map (make-sparse-keymap "Errors")))
1159 (define-key map [stop-subjob]
1160 '("Stop Compilation" . comint-interrupt-subjob))
1161 (define-key map [compilation-mode-separator2]
1162 '("----" . nil))
1163 (define-key map [compilation-mode-first-error]
1164 '("First Error" . first-error))
1165 (define-key map [compilation-mode-previous-error]
1166 '("Previous Error" . previous-error))
1167 (define-key map [compilation-mode-next-error]
1168 '("Next Error" . next-error))
1169 map))
1170
1139(defvar compilation-minor-mode-map 1171(defvar compilation-minor-mode-map
1140 (let ((map (make-sparse-keymap))) 1172 (let ((map (make-sparse-keymap)))
1141 (define-key map [mouse-2] 'compile-mouse-goto-error) 1173 (define-key map [mouse-2] 'compile-mouse-goto-error)
@@ -1146,6 +1178,9 @@ exited abnormally with code %d\n"
1146 (define-key map "\M-p" 'compilation-previous-error) 1178 (define-key map "\M-p" 'compilation-previous-error)
1147 (define-key map "\M-{" 'compilation-previous-file) 1179 (define-key map "\M-{" 'compilation-previous-file)
1148 (define-key map "\M-}" 'compilation-next-file) 1180 (define-key map "\M-}" 'compilation-next-file)
1181 ;; Set up the menu-bar
1182 (define-key map [menu-bar compilation]
1183 (cons "Errors" compilation-menu-map))
1149 map) 1184 map)
1150 "Keymap for `compilation-minor-mode'.") 1185 "Keymap for `compilation-minor-mode'.")
1151 1186
@@ -1158,50 +1193,30 @@ exited abnormally with code %d\n"
1158 (define-key map "\M-{" 'compilation-previous-file) 1193 (define-key map "\M-{" 'compilation-previous-file)
1159 (define-key map "\M-}" 'compilation-next-file) 1194 (define-key map "\M-}" 'compilation-next-file)
1160 ;; Set up the menu-bar 1195 ;; Set up the menu-bar
1161 (define-key map [menu-bar errors-menu] 1196 (define-key map [menu-bar compilation]
1162 (cons "Errors" (make-sparse-keymap "Errors"))) 1197 (cons "Errors" compilation-menu-map))
1163 (define-key map [menu-bar errors-menu stop-subjob]
1164 '("Stop" . comint-interrupt-subjob))
1165 (define-key map [menu-bar errors-menu compilation-mode-separator2]
1166 '("----" . nil))
1167 (define-key map [menu-bar errors-menu compilation-mode-first-error]
1168 '("First Error" . first-error))
1169 (define-key map [menu-bar errors-menu compilation-mode-previous-error]
1170 '("Previous Error" . previous-error))
1171 (define-key map [menu-bar errors-menu compilation-mode-next-error]
1172 '("Next Error" . next-error))
1173 map) 1198 map)
1174 "Keymap for `compilation-shell-minor-mode'.") 1199 "Keymap for `compilation-shell-minor-mode'.")
1175 1200
1176(defvar compilation-mode-map 1201(defvar compilation-mode-map
1177 (let ((map (cons 'keymap compilation-minor-mode-map))) 1202 (let ((map (make-sparse-keymap)))
1203 (set-keymap-parent map compilation-minor-mode-map)
1178 (define-key map " " 'scroll-up) 1204 (define-key map " " 'scroll-up)
1179 (define-key map "\^?" 'scroll-down) 1205 (define-key map "\^?" 'scroll-down)
1180 ;; Set up the menu-bar 1206 ;; Set up the menu-bar
1181 (define-key map [menu-bar compilation-menu] 1207 (define-key map [menu-bar compilation]
1182 (cons "Compile" (make-sparse-keymap "Compile"))) 1208 (cons "Compile" (make-sparse-keymap "Compile")))
1183 1209 (define-key map [menu-bar compilation compilation-separator2]
1184 (define-key map [menu-bar compilation-menu compilation-mode-kill-compilation]
1185 '("Stop Compilation" . kill-compilation))
1186 (define-key map [menu-bar compilation-menu compilation-mode-separator2]
1187 '("----" . nil)) 1210 '("----" . nil))
1188 (define-key map [menu-bar compilation-menu compilation-mode-first-error] 1211 (define-key map [menu-bar compilation compilation-mode-grep]
1189 '("First Error" . first-error))
1190 (define-key map [menu-bar compilation-menu compilation-mode-previous-error]
1191 '("Previous Error" . previous-error))
1192 (define-key map [menu-bar compilation-menu compilation-mode-next-error]
1193 '("Next Error" . next-error))
1194 (define-key map [menu-bar compilation-menu compilation-separator2]
1195 '("----" . nil))
1196 (define-key map [menu-bar compilation-menu compilation-mode-grep]
1197 '("Search Files (grep)" . grep)) 1212 '("Search Files (grep)" . grep))
1198 (define-key map [menu-bar compilation-menu compilation-mode-recompile] 1213 (define-key map [menu-bar compilation compilation-mode-recompile]
1199 '("Recompile" . recompile)) 1214 '("Recompile" . recompile))
1200 (define-key map [menu-bar compilation-menu compilation-mode-compile] 1215 (define-key map [menu-bar compilation compilation-mode-compile]
1201 '("Compile..." . compile)) 1216 '("Compile..." . compile))
1202 map) 1217 map)
1203 "Keymap for compilation log buffers. 1218 "Keymap for compilation log buffers.
1204`compilation-minor-mode-map' is a cdr of this.") 1219`compilation-minor-mode-map' is a parent of this.")
1205 1220
1206(put 'compilation-mode 'mode-class 'special) 1221(put 'compilation-mode 'mode-class 'special)
1207 1222
@@ -1241,63 +1256,28 @@ Runs `compilation-mode-hook' with `run-hooks' (which see)."
1241 (make-local-variable 'compilation-error-screen-columns) 1256 (make-local-variable 'compilation-error-screen-columns)
1242 (setq compilation-last-buffer (current-buffer))) 1257 (setq compilation-last-buffer (current-buffer)))
1243 1258
1244(defvar compilation-shell-minor-mode nil
1245 "Non-nil when in `compilation-shell-minor-mode'.
1246In this minor mode, all the error-parsing commands of the
1247Compilation major mode are available but bound to keys that don't
1248collide with Shell mode.")
1249(make-variable-buffer-local 'compilation-shell-minor-mode)
1250
1251(or (assq 'compilation-shell-minor-mode minor-mode-alist)
1252 (setq minor-mode-alist
1253 (cons '(compilation-shell-minor-mode " Shell-Compile")
1254 minor-mode-alist)))
1255(or (assq 'compilation-shell-minor-mode minor-mode-map-alist)
1256 (setq minor-mode-map-alist (cons (cons 'compilation-shell-minor-mode
1257 compilation-shell-minor-mode-map)
1258 minor-mode-map-alist)))
1259
1260(defvar compilation-minor-mode nil
1261 "Non-nil when in `compilation-minor-mode'.
1262In this minor mode, all the error-parsing commands of the
1263Compilation major mode are available.")
1264(make-variable-buffer-local 'compilation-minor-mode)
1265
1266(or (assq 'compilation-minor-mode minor-mode-alist)
1267 (setq minor-mode-alist (cons '(compilation-minor-mode " Compilation")
1268 minor-mode-alist)))
1269(or (assq 'compilation-minor-mode minor-mode-map-alist)
1270 (setq minor-mode-map-alist (cons (cons 'compilation-minor-mode
1271 compilation-minor-mode-map)
1272 minor-mode-map-alist)))
1273
1274;;;###autoload 1259;;;###autoload
1275(defun compilation-shell-minor-mode (&optional arg) 1260(define-minor-mode compilation-shell-minor-mode
1276 "Toggle compilation shell minor mode. 1261 "Toggle compilation shell minor mode.
1277With arg, turn compilation mode on if and only if arg is positive. 1262With arg, turn compilation mode on if and only if arg is positive.
1278See `compilation-mode'. 1263In this minor mode, all the error-parsing commands of the
1264Compilation major mode are available but bound to keys that don't
1265collide with Shell mode. See `compilation-mode'.
1279Turning the mode on runs the normal hook `compilation-shell-minor-mode-hook'." 1266Turning the mode on runs the normal hook `compilation-shell-minor-mode-hook'."
1280 (interactive "P") 1267 nil " Shell-Compile" nil
1281 (if (setq compilation-shell-minor-mode (if (null arg) 1268 (let (mode-line-process)
1282 (null compilation-shell-minor-mode) 1269 (compilation-setup)))
1283 (> (prefix-numeric-value arg) 0)))
1284 (let ((mode-line-process))
1285 (compilation-setup)
1286 (run-hooks 'compilation-shell-minor-mode-hook))))
1287 1270
1288;;;###autoload 1271;;;###autoload
1289(defun compilation-minor-mode (&optional arg) 1272(define-minor-mode compilation-minor-mode
1290 "Toggle compilation minor mode. 1273 "Toggle compilation minor mode.
1291With arg, turn compilation mode on if and only if arg is positive. 1274With arg, turn compilation mode on if and only if arg is positive.
1292See `compilation-mode'. 1275In this minor mode, all the error-parsing commands of the
1276Compilation major mode are available. See `compilation-mode'.
1293Turning the mode on runs the normal hook `compilation-minor-mode-hook'." 1277Turning the mode on runs the normal hook `compilation-minor-mode-hook'."
1294 (interactive "P") 1278 nil " Compilation" nil
1295 (if (setq compilation-minor-mode (if (null arg) 1279 (let ((mode-line-process))
1296 (null compilation-minor-mode) 1280 (compilation-setup)))
1297 (> (prefix-numeric-value arg) 0)))
1298 (let ((mode-line-process))
1299 (compilation-setup)
1300 (run-hooks 'compilation-minor-mode-hook))))
1301 1281
1302(defun compilation-handle-exit (process-status exit-status msg) 1282(defun compilation-handle-exit (process-status exit-status msg)
1303 "Write msg in the current buffer and hack its mode-line-process." 1283 "Write msg in the current buffer and hack its mode-line-process."