aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2020-05-03 16:53:53 +0300
committerEli Zaretskii2020-05-03 16:53:53 +0300
commitcb1e73d1bc964f61626955e950e660602f2014f5 (patch)
tree0c2f6be31ee2d17754c996c9973d529d22ff1297
parent63268253d21c57d991cba3f3b083d74f154a26fe (diff)
downloademacs-cb1e73d1bc964f61626955e950e660602f2014f5.tar.gz
emacs-cb1e73d1bc964f61626955e950e660602f2014f5.zip
Improve accuracy of apropos commands that search doc strings
It is conceptually wrong for apropos commands that search doc strings to look for matches of several words only on the same line, because division of doc strings between lines is ephemeral. * lisp/apropos.el (apropos-parse-pattern): Accept an optional argument MULTILINE-P, and if that is non-nil, produce regexps that match words in the list even if they are separated by line boundaries. (apropos-value, apropos-local-value, apropos-documentation): Use the new optional argument in apropos commands that search multiline text, such as doc strings. * src/search.c (Fposix_looking_at, Fposix_string_match) (Fposix_search_backward, Fposix_search_forward): Make sure Posix appears in the doc strings near REGEXP, for better matches.
-rw-r--r--lisp/apropos.el21
-rw-r--r--src/search.c10
2 files changed, 20 insertions, 11 deletions
diff --git a/lisp/apropos.el b/lisp/apropos.el
index e40f94ccb8c..7cbda3cb678 100644
--- a/lisp/apropos.el
+++ b/lisp/apropos.el
@@ -373,9 +373,11 @@ kind of objects to search."
373 (user-error "No word list given")) 373 (user-error "No word list given"))
374 pattern))) 374 pattern)))
375 375
376(defun apropos-parse-pattern (pattern) 376(defun apropos-parse-pattern (pattern &optional multiline-p)
377 "Rewrite a list of words to a regexp matching all permutations. 377 "Rewrite a list of words to a regexp matching all permutations.
378If PATTERN is a string, that means it is already a regexp. 378If PATTERN is a string, that means it is already a regexp.
379MULTILINE-P, if non-nil, means produce a regexp that will match
380the words even if separated by newlines.
379This updates variables `apropos-pattern', `apropos-pattern-quoted', 381This updates variables `apropos-pattern', `apropos-pattern-quoted',
380`apropos-regexp', `apropos-words', and `apropos-all-words-regexp'." 382`apropos-regexp', `apropos-words', and `apropos-all-words-regexp'."
381 (setq apropos-words nil 383 (setq apropos-words nil
@@ -386,6 +388,9 @@ This updates variables `apropos-pattern', `apropos-pattern-quoted',
386 ;; any combination of two or more words like this: 388 ;; any combination of two or more words like this:
387 ;; (a|b|c).*(a|b|c) which may give some false matches, 389 ;; (a|b|c).*(a|b|c) which may give some false matches,
388 ;; but as long as it also gives the right ones, that's ok. 390 ;; but as long as it also gives the right ones, that's ok.
391 ;; (Actually, when MULTILINE-P is non-nil, instead of '.' we
392 ;; use a trick that would find a match even if the words are
393 ;; on different lines.
389 (let ((words pattern)) 394 (let ((words pattern))
390 (setq apropos-pattern (mapconcat 'identity pattern " ") 395 (setq apropos-pattern (mapconcat 'identity pattern " ")
391 apropos-pattern-quoted (regexp-quote apropos-pattern)) 396 apropos-pattern-quoted (regexp-quote apropos-pattern))
@@ -402,9 +407,13 @@ This updates variables `apropos-pattern', `apropos-pattern-quoted',
402 (setq apropos-words (cons s apropos-words) 407 (setq apropos-words (cons s apropos-words)
403 apropos-all-words (cons a apropos-all-words)))) 408 apropos-all-words (cons a apropos-all-words))))
404 (setq apropos-all-words-regexp 409 (setq apropos-all-words-regexp
405 (apropos-words-to-regexp apropos-all-words ".+")) 410 (apropos-words-to-regexp apropos-all-words
411 ;; The [^b-a] trick matches any
412 ;; character including a newline.
413 (if multiline-p "[^b-a]+?" ".+")))
406 (setq apropos-regexp 414 (setq apropos-regexp
407 (apropos-words-to-regexp apropos-words ".*?"))) 415 (apropos-words-to-regexp apropos-words
416 (if multiline-p "[^b-a]*?" ".*?"))))
408 (setq apropos-pattern-quoted (regexp-quote pattern) 417 (setq apropos-pattern-quoted (regexp-quote pattern)
409 apropos-all-words-regexp pattern 418 apropos-all-words-regexp pattern
410 apropos-pattern pattern 419 apropos-pattern pattern
@@ -787,7 +796,7 @@ Returns list of symbols and values found."
787 (interactive (list (apropos-read-pattern "value") 796 (interactive (list (apropos-read-pattern "value")
788 current-prefix-arg)) 797 current-prefix-arg))
789 (setq apropos--current (list #'apropos-value pattern do-all)) 798 (setq apropos--current (list #'apropos-value pattern do-all))
790 (apropos-parse-pattern pattern) 799 (apropos-parse-pattern pattern t)
791 (or do-all (setq do-all apropos-do-all)) 800 (or do-all (setq do-all apropos-do-all))
792 (setq apropos-accumulator ()) 801 (setq apropos-accumulator ())
793 (let (f v p) 802 (let (f v p)
@@ -827,7 +836,7 @@ Optional arg BUFFER (default: current buffer) is the buffer to check."
827 (interactive (list (apropos-read-pattern "value of buffer-local variable"))) 836 (interactive (list (apropos-read-pattern "value of buffer-local variable")))
828 (unless buffer (setq buffer (current-buffer))) 837 (unless buffer (setq buffer (current-buffer)))
829 (setq apropos--current (list #'apropos-local-value pattern buffer)) 838 (setq apropos--current (list #'apropos-local-value pattern buffer))
830 (apropos-parse-pattern pattern) 839 (apropos-parse-pattern pattern t)
831 (setq apropos-accumulator ()) 840 (setq apropos-accumulator ())
832 (let ((var nil)) 841 (let ((var nil))
833 (mapatoms 842 (mapatoms
@@ -869,7 +878,7 @@ Returns list of symbols and documentation found."
869 (interactive (list (apropos-read-pattern "documentation") 878 (interactive (list (apropos-read-pattern "documentation")
870 current-prefix-arg)) 879 current-prefix-arg))
871 (setq apropos--current (list #'apropos-documentation pattern do-all)) 880 (setq apropos--current (list #'apropos-documentation pattern do-all))
872 (apropos-parse-pattern pattern) 881 (apropos-parse-pattern pattern t)
873 (or do-all (setq do-all apropos-do-all)) 882 (or do-all (setq do-all apropos-do-all))
874 (setq apropos-accumulator () apropos-files-scanned ()) 883 (setq apropos-accumulator () apropos-files-scanned ())
875 (let ((standard-input (get-buffer-create " apropos-temp")) 884 (let ((standard-input (get-buffer-create " apropos-temp"))
diff --git a/src/search.c b/src/search.c
index 567270a84cb..ec076c18035 100644
--- a/src/search.c
+++ b/src/search.c
@@ -353,8 +353,8 @@ data if you want to preserve them. */)
353} 353}
354 354
355DEFUN ("posix-looking-at", Fposix_looking_at, Sposix_looking_at, 1, 1, 0, 355DEFUN ("posix-looking-at", Fposix_looking_at, Sposix_looking_at, 1, 1, 0,
356 doc: /* Return t if text after point matches regular expression REGEXP. 356 doc: /* Return t if text after point matches REGEXP according to Posix rules.
357Find the longest match, in accord with Posix regular expression rules. 357Find the longest match, in accordance with Posix regular expression rules.
358This function modifies the match data that `match-beginning', 358This function modifies the match data that `match-beginning',
359`match-end' and `match-data' access; save and restore the match 359`match-end' and `match-data' access; save and restore the match
360data if you want to preserve them. */) 360data if you want to preserve them. */)
@@ -449,7 +449,7 @@ matched by the parenthesis constructions in REGEXP. */)
449} 449}
450 450
451DEFUN ("posix-string-match", Fposix_string_match, Sposix_string_match, 2, 3, 0, 451DEFUN ("posix-string-match", Fposix_string_match, Sposix_string_match, 2, 3, 0,
452 doc: /* Return index of start of first match for REGEXP in STRING, or nil. 452 doc: /* Return index of start of first match for Posix REGEXP in STRING, or nil.
453Find the longest match, in accord with Posix regular expression rules. 453Find the longest match, in accord with Posix regular expression rules.
454Case is ignored if `case-fold-search' is non-nil in the current buffer. 454Case is ignored if `case-fold-search' is non-nil in the current buffer.
455If third arg START is non-nil, start search at that index in STRING. 455If third arg START is non-nil, start search at that index in STRING.
@@ -2276,7 +2276,7 @@ and `replace-match'. */)
2276 2276
2277DEFUN ("posix-search-backward", Fposix_search_backward, Sposix_search_backward, 1, 4, 2277DEFUN ("posix-search-backward", Fposix_search_backward, Sposix_search_backward, 1, 4,
2278 "sPosix search backward: ", 2278 "sPosix search backward: ",
2279 doc: /* Search backward from point for match for regular expression REGEXP. 2279 doc: /* Search backward from point for match for REGEXP according to Posix rules.
2280Find the longest match in accord with Posix regular expression rules. 2280Find the longest match in accord with Posix regular expression rules.
2281Set point to the beginning of the occurrence found, and return point. 2281Set point to the beginning of the occurrence found, and return point.
2282An optional second argument bounds the search; it is a buffer position. 2282An optional second argument bounds the search; it is a buffer position.
@@ -2304,7 +2304,7 @@ and `replace-match'. */)
2304 2304
2305DEFUN ("posix-search-forward", Fposix_search_forward, Sposix_search_forward, 1, 4, 2305DEFUN ("posix-search-forward", Fposix_search_forward, Sposix_search_forward, 1, 4,
2306 "sPosix search: ", 2306 "sPosix search: ",
2307 doc: /* Search forward from point for regular expression REGEXP. 2307 doc: /* Search forward from point for REGEXP according to Posix rules.
2308Find the longest match in accord with Posix regular expression rules. 2308Find the longest match in accord with Posix regular expression rules.
2309Set point to the end of the occurrence found, and return point. 2309Set point to the end of the occurrence found, and return point.
2310An optional second argument bounds the search; it is a buffer position. 2310An optional second argument bounds the search; it is a buffer position.