commit a710f8aa61ca73054109dc4f926d1ac6aabdd849 (HEAD, refs/remotes/origin/master) Author: Juri Linkov Date: Tue Feb 6 23:39:00 2018 +0200 * lisp/comint.el (comint-history-isearch-setup): Check if process is live. Don't activate comint-history isearch when shell prompt is empty like in all *Async Shell Command* buffers. (Bug#30187) diff --git a/lisp/comint.el b/lisp/comint.el index 8dba317099..b4fbfc86ed 100644 --- a/lisp/comint.el +++ b/lisp/comint.el @@ -1448,10 +1448,17 @@ If nil, Isearch operates on the whole comint buffer." (defun comint-history-isearch-setup () "Set up a comint for using Isearch to search the input history. Intended to be added to `isearch-mode-hook' in `comint-mode'." - (when (or (eq comint-history-isearch t) - (and (eq comint-history-isearch 'dwim) - ;; Point is at command line. - (comint-after-pmark-p))) + (when (and (get-buffer-process (current-buffer)) + (or (eq comint-history-isearch t) + (and (eq comint-history-isearch 'dwim) + ;; Point is at command line. + (comint-after-pmark-p) + ;; Prompt is not empty like in Async Shell Command buffers + (not (eq (save-excursion + (goto-char (comint-line-beginning-position)) + (forward-line 0) + (point)) + (comint-line-beginning-position)))))) (setq isearch-message-prefix-add "history ") (setq-local isearch-search-fun-function #'comint-history-isearch-search) commit 03722339060c7654e839d586cd9facc69593ddce Author: Juri Linkov Date: Tue Feb 6 23:32:08 2018 +0200 * lisp/dired.el (dired-get-marked-files): Add new optional arg 'error'. Call user-error when it's non-nil and result is empty (bug#30285). * lisp/dired-aux.el (dired-do-chxxx, dired-do-chmod) (dired-do-print, dired-do-async-shell-command) (dired-do-shell-command, dired-do-compress-to) (dired-mark-confirm, dired-do-create-files) (dired-do-isearch, dired-do-isearch-regexp) (dired-do-query-replace-regexp, dired-do-find-regexp): * lisp/dired-x.el (dired-do-find-marked-files): Set arg 'error' of dired-get-marked-files call to t. diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el index 55b68a372e..6e3e336009 100644 --- a/lisp/dired-aux.el +++ b/lisp/dired-aux.el @@ -301,7 +301,7 @@ List has a form of (file-name full-file-name (attribute-list))." ;; PROGRAM is the program used to change the attribute. ;; OP-SYMBOL is the type of operation (for use in `dired-mark-pop-up'). ;; ARG describes which files to use, as in `dired-get-marked-files'. - (let* ((files (dired-get-marked-files t arg)) + (let* ((files (dired-get-marked-files t arg nil nil t)) ;; The source of default file attributes is the file at point. (default-file (dired-get-filename t t)) (default (when default-file @@ -361,7 +361,7 @@ Symbolic modes like `g+w' are allowed. Type M-n to pull the file attributes of the file at point into the minibuffer." (interactive "P") - (let* ((files (dired-get-marked-files t arg)) + (let* ((files (dired-get-marked-files t arg nil nil t)) ;; The source of default file attributes is the file at point. (default-file (dired-get-filename t t)) (modestr (when default-file @@ -476,7 +476,7 @@ Uses the shell command coming from variables `lpr-command' and `lpr-switches' as default." (interactive "P") (require 'lpr) - (let* ((file-list (dired-get-marked-files t arg)) + (let* ((file-list (dired-get-marked-files t arg nil nil t)) (lpr-switches (if (and (stringp printer-name) (string< "" printer-name)) @@ -666,7 +666,7 @@ In shell syntax this means separating the individual commands with `;'. The output appears in the buffer `*Async Shell Command*'." (interactive - (let ((files (dired-get-marked-files t current-prefix-arg))) + (let ((files (dired-get-marked-files t current-prefix-arg nil nil t))) (list ;; Want to give feedback whether this file or marked files are used: (dired-read-shell-command "& on %s: " current-prefix-arg files) @@ -727,7 +727,7 @@ can be produced by `dired-get-marked-files', for example." ;;Functions dired-run-shell-command and dired-shell-stuff-it do the ;;actual work and can be redefined for customization. (interactive - (let ((files (dired-get-marked-files t current-prefix-arg))) + (let ((files (dired-get-marked-files t current-prefix-arg nil nil t))) (list ;; Want to give feedback whether this file or marked files are used: (dired-read-shell-command "! on %s: " current-prefix-arg files) @@ -1030,7 +1030,7 @@ Prompt for the archive file name. Choose the archiving command based on the archive file-name extension and `dired-compress-files-alist'." (interactive) - (let* ((in-files (dired-get-marked-files)) + (let* ((in-files (dired-get-marked-files nil nil nil nil t)) (out-file (expand-file-name (read-file-name "Compress to: "))) (rule (cl-find-if (lambda (x) @@ -1153,7 +1153,7 @@ Return nil if no change in files." ;; Pass t for DISTINGUISH-ONE-MARKED so that a single file which ;; is marked pops up a window. That will help the user see ;; it isn't the current line file. - (let ((files (dired-get-marked-files t arg nil t)) + (let ((files (dired-get-marked-files t arg nil t t)) (string (if (eq op-symbol 'compress) "Compress or uncompress" (capitalize (symbol-name op-symbol))))) (dired-mark-pop-up nil op-symbol files #'y-or-n-p @@ -1845,7 +1845,7 @@ Optional arg HOW-TO determines how to treat the target. The rest of into-dir are optional arguments. For any other return value, TARGET is treated as a directory." (or op1 (setq op1 operation)) - (let* ((fn-list (dired-get-marked-files nil arg)) + (let* ((fn-list (dired-get-marked-files nil arg nil nil t)) (rfn-list (mapcar #'dired-make-relative fn-list)) (dired-one-file ; fluid variable inside dired-create-files (and (consp fn-list) (null (cdr fn-list)) (car fn-list))) @@ -2799,14 +2799,14 @@ is part of a file name (i.e., has the text property `dired-filename')." "Search for a string through all marked files using Isearch." (interactive) (multi-isearch-files - (dired-get-marked-files nil nil 'dired-nondirectory-p))) + (dired-get-marked-files nil nil 'dired-nondirectory-p nil t))) ;;;###autoload (defun dired-do-isearch-regexp () "Search for a regexp through all marked files using Isearch." (interactive) (multi-isearch-files-regexp - (dired-get-marked-files nil nil 'dired-nondirectory-p))) + (dired-get-marked-files nil nil 'dired-nondirectory-p nil t))) ;;;###autoload (defun dired-do-search (regexp) @@ -2827,7 +2827,7 @@ with the command \\[tags-loop-continue]." (query-replace-read-args "Query replace regexp in marked files" t t))) (list (nth 0 common) (nth 1 common) (nth 2 common)))) - (dolist (file (dired-get-marked-files nil nil 'dired-nondirectory-p)) + (dolist (file (dired-get-marked-files nil nil 'dired-nondirectory-p nil t)) (let ((buffer (get-file-buffer file))) (if (and buffer (with-current-buffer buffer buffer-read-only)) @@ -2851,7 +2851,7 @@ REGEXP should use constructs supported by your local `grep' command." (require 'grep) (defvar grep-find-ignored-files) (defvar grep-find-ignored-directories) - (let* ((files (dired-get-marked-files)) + (let* ((files (dired-get-marked-files nil nil nil nil t)) (ignores (nconc (mapcar (lambda (s) (concat s "/")) grep-find-ignored-directories) diff --git a/lisp/dired-x.el b/lisp/dired-x.el index a90f1f4adc..fa36083e14 100644 --- a/lisp/dired-x.el +++ b/lisp/dired-x.el @@ -1335,7 +1335,8 @@ displayed this way is restricted by the height of the current window and To keep Dired buffer displayed, type \\[split-window-below] first. To display just marked files, type \\[delete-other-windows] first." (interactive "P") - (dired-simultaneous-find-file (dired-get-marked-files) noselect)) + (dired-simultaneous-find-file (dired-get-marked-files nil nil nil nil t) + noselect)) (defun dired-simultaneous-find-file (file-list noselect) "Visit all files in FILE-LIST and display them simultaneously. diff --git a/lisp/dired.el b/lisp/dired.el index eade11bc7f..ef069d2345 100644 --- a/lisp/dired.el +++ b/lisp/dired.el @@ -645,7 +645,7 @@ marked file, return (t FILENAME) instead of (FILENAME)." ;; save-excursion loses, again (dired-move-to-filename))) -(defun dired-get-marked-files (&optional localp arg filter distinguish-one-marked) +(defun dired-get-marked-files (&optional localp arg filter distinguish-one-marked error) "Return the marked files' names as list of strings. The list is in the same order as the buffer, that is, the car is the first marked file. @@ -662,7 +662,10 @@ Optional third argument FILTER, if non-nil, is a function to select If DISTINGUISH-ONE-MARKED is non-nil, then if we find just one marked file, return (t FILENAME) instead of (FILENAME). -Don't use that together with FILTER." +Don't use that together with FILTER. + +If ERROR is non-nil, signal an error when the list of found files is empty. +ERROR can be a string with the error message." (let ((all-of-them (save-excursion (delq nil (dired-map-over-marks @@ -672,13 +675,17 @@ Don't use that together with FILTER." (when (equal all-of-them '(t)) (setq all-of-them nil)) (if (not filter) - (if (and distinguish-one-marked (eq (car all-of-them) t)) - all-of-them - (nreverse all-of-them)) + (setq result + (if (and distinguish-one-marked (eq (car all-of-them) t)) + all-of-them + (nreverse all-of-them))) (dolist (file all-of-them) (if (funcall filter file) - (push file result))) - result))) + (push file result)))) + (when (and (null result) error) + (user-error (if (stringp error) error "No files specified"))) + result)) + ;; The dired command commit 109237e23a01901e70c70c41166ebefc26b1b24f Author: Juri Linkov Date: Tue Feb 6 23:24:42 2018 +0200 ; Small fixes and indentation diff --git a/ChangeLog.2 b/ChangeLog.2 index 22c7e0116b..356fbc788f 100644 --- a/ChangeLog.2 +++ b/ChangeLog.2 @@ -25940,9 +25940,9 @@ 2015-08-19 Artur Malabarba * lisp/isearch.el (isearch-search-fun-default): Revert a5bdb87 - Remove usage of `isearch-lax-whitespace' inside the `iearch-word' + Remove usage of `isearch-lax-whitespace' inside the `isearch-word' clause of `isearch-search-fun-default'. That lax variable does not - refer to lax-whitespacing. Related to (bug#21777). + refer to lax-whitespacing. Related to (bug#21277). This reverts commit a5bdb872edb9f031fe041faf9a8c0be432e5f64c. * lisp/character-fold.el (character-fold-search): Set to nil. Default to nil for now, until someone implements proper @@ -29096,7 +29096,7 @@ * lisp/isearch.el: Move character-folding code to character-fold.el (isearch-toggle-character-fold): New command. - (isearch-mode-map): Bind it to "\M-sf". + (isearch-mode-map): Bind it to "\M-s'". (isearch-mode): Check value of `character-fold-search'. 2015-06-24 Stefan Monnier diff --git a/lisp/isearch.el b/lisp/isearch.el index 729f629423..41350c2d30 100644 --- a/lisp/isearch.el +++ b/lisp/isearch.el @@ -589,8 +589,8 @@ variable by the command `isearch-toggle-lax-whitespace'.") (defvar isearch-cmds nil "Stack of search status elements. Each element is an `isearch--state' struct where the slots are - [STRING MESSAGE POINT SUCCESS FORWARD OTHER-END WORD - ERROR WRAPPED BARRIER CASE-FOLD-SEARCH]") + [STRING MESSAGE POINT SUCCESS FORWARD OTHER-END WORD/REGEXP-FUNCTION + ERROR WRAPPED BARRIER CASE-FOLD-SEARCH POP-FUN]") (defvar isearch-string "") ; The current search string. (defvar isearch-message "") ; text-char-description version of isearch-string diff --git a/lisp/replace.el b/lisp/replace.el index c6892328d7..c28c9b36f0 100644 --- a/lisp/replace.el +++ b/lisp/replace.el @@ -39,7 +39,7 @@ (defcustom replace-char-fold nil "Non-nil means replacement commands should do character folding in matches. This means, for instance, that \\=' will match a large variety of -unicode quotes. +Unicode quotes. This variable affects `query-replace' and `replace-string', but not `replace-regexp'." :type 'boolean @@ -1638,11 +1638,11 @@ See also `multi-occur'." (inhibit-field-text-motion t) (headerpt (with-current-buffer out-buf (point)))) (with-current-buffer buf - ;; The following binding is for when case-fold-search - ;; has a local binding in the original buffer, in which - ;; case we cannot bind it globally and let that have - ;; effect in every buffer we search. - (let ((case-fold-search case-fold)) + ;; The following binding is for when case-fold-search + ;; has a local binding in the original buffer, in which + ;; case we cannot bind it globally and let that have + ;; effect in every buffer we search. + (let ((case-fold-search case-fold)) (or coding ;; Set CODING only if the current buffer locally ;; binds buffer-file-coding-system. @@ -1708,9 +1708,9 @@ See also `multi-occur'." ;; at the end of the prefix ;; (for Occur Edit mode). front-sticky t - rear-nonsticky t - occur-target ,marker - follow-link t + rear-nonsticky t + occur-target ,marker + follow-link t help-echo "mouse-2: go to this occurrence")))) (match-str ;; We don't put `mouse-face' on the newline, @@ -1730,7 +1730,7 @@ See also `multi-occur'." "\n" (if prefix-face (propertize - "\n :" 'font-lock-face prefix-face) + "\n :" 'font-lock-face prefix-face) "\n :") match-str) ;; Add marker at eol, but no mouse props. @@ -1777,7 +1777,7 @@ See also `multi-occur'." (setq curr-line (+ curr-line (count-lines begpt endpt) ;; Add 1 for empty last match line ;; since count-lines returns one - ;; line less. + ;; line less. (if (and (bolp) (eolp)) 1 0))) ;; On to the next match... (forward-line 1)) @@ -1820,16 +1820,16 @@ See also `multi-occur'." (if (= lines matches) "" (format " in %d line%s" lines - (if (= lines 1) "" "s"))) + (if (= lines 1) "" "s"))) ;; Don't display regexp for multi-buffer. (if (> (length buffers) 1) "" (occur-regexp-descr regexp)) (buffer-name buf) - (if in-region-p - (format " within region: %d-%d" - occur--region-start - occur--region-end) - "")) + (if in-region-p + (format " within region: %d-%d" + occur--region-start + occur--region-end) + "")) 'read-only t)) (setq end (point)) (add-text-properties beg end `(occur-title ,buf)) @@ -2220,9 +2220,9 @@ It is called with three arguments, as if it were ;; used after `recursive-edit' might override them. (let* ((isearch-regexp regexp-flag) (isearch-regexp-function (or delimited-flag - (and replace-char-fold - (not regexp-flag) - #'char-fold-to-regexp))) + (and replace-char-fold + (not regexp-flag) + #'char-fold-to-regexp))) (isearch-lax-whitespace replace-lax-whitespace) (isearch-regexp-lax-whitespace commit 31350817ae6eda2e071dbc28f1f1edc50e5f3b0c Author: Juri Linkov Date: Tue Feb 6 23:20:10 2018 +0200 Support occur command operating on the region from Isearch. * lisp/isearch.el (isearch-occur): Use region-bounds as region arg of occur. (isearch-query-replace): Use use-region-p. * lisp/replace.el (occur--region-start-line): Rename from occur--matches-threshold. (occur): Use complete lines when region is active for line-oriented occur. (occur-engine): Count lines either from occur--region-start-line or 1. diff --git a/lisp/isearch.el b/lisp/isearch.el index 9297c0f95b..729f629423 100644 --- a/lisp/isearch.el +++ b/lisp/isearch.el @@ -1853,11 +1853,11 @@ replacements from Isearch is `M-s w ... M-%'." (concat "Query replace" (isearch--describe-regexp-mode (or delimited isearch-regexp-function) t) (if backward " backward" "") - (if (and transient-mark-mode mark-active) " in region" "")) + (if (use-region-p) " in region" "")) isearch-regexp) t isearch-regexp (or delimited isearch-regexp-function) nil nil - (if (and transient-mark-mode mark-active) (region-beginning)) - (if (and transient-mark-mode mark-active) (region-end)) + (if (use-region-p) (region-beginning)) + (if (use-region-p) (region-end)) backward)) (and isearch-recursive-edit (exit-recursive-edit))) @@ -1920,7 +1920,8 @@ characters in that string." 'isearch-regexp-function-descr (isearch--describe-regexp-mode isearch-regexp-function)) regexp) - nlines))) + nlines + (if (use-region-p) (region-bounds))))) (declare-function hi-lock-read-face-name "hi-lock" ()) diff --git a/lisp/replace.el b/lisp/replace.el index 0efd082096..c6892328d7 100644 --- a/lisp/replace.el +++ b/lisp/replace.el @@ -1387,7 +1387,7 @@ invoke `occur'." ;; Region limits when `occur' applies on a region. (defvar occur--region-start nil) (defvar occur--region-end nil) -(defvar occur--matches-threshold nil) +(defvar occur--region-start-line nil) (defvar occur--orig-line nil) (defvar occur--final-pos nil) @@ -1441,13 +1441,15 @@ is not modified." (or end (setq end (point-max)))) (let ((occur--region-start start) (occur--region-end end) - (occur--matches-threshold + (occur--region-start-line (and in-region-p (line-number-at-pos (min start end)))) (occur--orig-line (line-number-at-pos (point)))) (save-excursion ; If no matches `occur-1' doesn't restore the point. - (and in-region-p (narrow-to-region start end)) + (and in-region-p (narrow-to-region + (save-excursion (goto-char start) (line-beginning-position)) + (save-excursion (goto-char end) (line-end-position)))) (occur-1 regexp nlines (list (current-buffer))) (and in-region-p (widen)))))) @@ -1621,7 +1623,7 @@ See also `multi-occur'." (let ((lines 0) ;; count of matching lines (matches 0) ;; count of matches (curr-line ;; line count - (or occur--matches-threshold 1)) + (or occur--region-start-line 1)) (orig-line occur--orig-line) (orig-line-shown-p) (prev-line nil) ;; line number of prev match endpt @@ -1754,7 +1756,7 @@ See also `multi-occur'." (setq orig-line-shown-p t) (save-excursion (goto-char (point-min)) - (forward-line (1- orig-line)) + (forward-line (- orig-line (or occur--region-start-line 1))) (occur-engine-line (line-beginning-position) (line-end-position) keep-props))))) ;; Actually insert the match display data @@ -1792,7 +1794,7 @@ See also `multi-occur'." (let ((orig-line-str (save-excursion (goto-char (point-min)) - (forward-line (1- orig-line)) + (forward-line (- orig-line (or occur--region-start-line 1))) (occur-engine-line (line-beginning-position) (line-end-position) keep-props)))) (add-face-text-property