all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Apropos commands and regexps
@ 2002-05-12  0:57 Kim F. Storm
  2002-05-12  5:28 ` Eli Zaretskii
                   ` (3 more replies)
  0 siblings, 4 replies; 56+ messages in thread
From: Kim F. Storm @ 2002-05-12  0:57 UTC (permalink / raw)



I was thinking about the use of regexps in connection with the various
apropos commands.

We often advise new users to use e.g. C-h a or M-x apropos (also
accessible through the Help menu).

However, these commands prompts like this:

        Apropos command (regexp):

which may be nonsense to some novice users.


Wouldn't it be simpler (for a novice user -- and for advanced users
too) to simply write one or more words (substrings) and then search
for all combinations of those words (substrings) in the relevant list.

E.g. C-h a open file RET  would find any matching

        open.*file and file.*open

BTW, this obvious example doesn't find `find-file' :-(
Maybe we should have a defalias open-file -> find-file ?

Of course, if the input is already a regexp (e.g. if it does not
contain any spaces), it should be used directly.  Below is a patch
to show the concept:

Index: apropos.el
===================================================================
RCS file: /cvs/emacs/lisp/apropos.el,v
retrieving revision 1.84
diff -c -r1.84 apropos.el
*** apropos.el	4 May 2002 14:51:16 -0000	1.84
--- apropos.el	11 May 2002 23:55:10 -0000
***************
*** 122,127 ****
--- 122,130 ----
  (defvar apropos-regexp nil
    "Regexp used in current apropos run.")
  
+ (defvar apropos-orig-regexp nil
+   "Regexp as entered by user.")
+ 
  (defvar apropos-files-scanned ()
    "List of elc files already scanned in current run of `apropos-documentation'.")
  
***************
*** 219,224 ****
--- 222,245 ----
      (and label button)))
  
  \f
+ (defun apropos-rewrite-regexp (regexp)
+   "Rewrite a list of words to a regexp matching all permutations.
+ If REGEXP is already a regexp, don't modify it."
+   (setq apropos-orig-regexp regexp)
+   (if (and (string-match " " regexp)
+ 	   (string-equal (regexp-quote regexp) regexp))
+       ;; We don't actually make a regexp matching all permutations.
+       ;; Instead, for e.g. "a b c", we make a regexp matching
+       ;; any combination of two or more words like this:
+       ;; (a|b|c).*(a|b|c) which may give some false matches,
+       ;; but as long as it also gives the right ones, that's ok.
+       (let ((words (split-string regexp "[ \t]+"))
+ 	    res)
+ 	(dolist (w words)
+ 	  (setq res (concat (or res "\\(") (if res "\\|" "") w)))
+ 	(concat res "\\).*" res "\\)"))
+     regexp))
+     
  ;;;###autoload
  (define-derived-mode apropos-mode fundamental-mode "Apropos"
    "Major mode for following hyperlinks in output of apropos commands.
***************
*** 262,267 ****
--- 283,289 ----
  				       "or function ")
  				   "(regexp): "))
  		     current-prefix-arg))
+   (setq apropos-regexp (apropos-rewrite-regexp apropos-regexp))
    (let ((message
  	 (let ((standard-output (get-buffer-create "*Apropos*")))
  	   (print-help-return-message 'identity))))
***************
*** 304,309 ****
--- 326,332 ----
  show unbound symbols and key bindings, which is a little more
  time-consuming.  Returns list of symbols and documentation found."
    (interactive "sApropos symbol (regexp): \nP")
+   (setq apropos-regexp (apropos-rewrite-regexp apropos-regexp))
    (setq apropos-accumulator
  	(apropos-internal apropos-regexp
  			  (and (not do-all)
***************
*** 371,376 ****
--- 394,400 ----
  at the function and at the names and values of properties.
  Returns list of symbols and values found."
    (interactive "sApropos value (regexp): \nP")
+   (setq apropos-regexp (apropos-rewrite-regexp apropos-regexp))
    (or do-all (setq do-all apropos-do-all))
    (setq apropos-accumulator ())
     (let (f v p)
***************
*** 397,402 ****
--- 421,427 ----
  bindings.
  Returns list of symbols and documentation found."
    (interactive "sApropos documentation (regexp): \nP")
+   (setq apropos-regexp (apropos-rewrite-regexp apropos-regexp))
    (or do-all (setq do-all apropos-do-all))
    (setq apropos-accumulator () apropos-files-scanned ())
    (let ((standard-input (get-buffer-create " apropos-temp"))
***************
*** 590,596 ****
  If SPACING is non-nil, it should be a string;
  separate items with that string."
    (if (null apropos-accumulator)
!       (message "No apropos matches for `%s'" apropos-regexp)
      (setq apropos-accumulator
  	  (sort apropos-accumulator (lambda (a b)
  				      (string-lessp (car a) (car b)))))
--- 615,621 ----
  If SPACING is non-nil, it should be a string;
  separate items with that string."
    (if (null apropos-accumulator)
!       (message "No apropos matches for `%s'" apropos-orig-regexp)
      (setq apropos-accumulator
  	  (sort apropos-accumulator (lambda (a b)
  				      (string-lessp (car a) (car b)))))


-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

^ permalink raw reply	[flat|nested] 56+ messages in thread

end of thread, other threads:[~2002-05-23 21:41 UTC | newest]

Thread overview: 56+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-05-12  0:57 Apropos commands and regexps Kim F. Storm
2002-05-12  5:28 ` Eli Zaretskii
2002-05-12  5:38   ` Eli Zaretskii
2002-05-13  1:40   ` Miles Bader
2002-05-13 19:18     ` Kim F. Storm
2002-05-14  5:55       ` Miles Bader
2002-05-13 19:11   ` Kim F. Storm
2002-05-14  5:38     ` Miles Bader
2002-05-15  7:00     ` Richard Stallman
2002-05-15 11:23       ` Miles Bader
2002-05-15 21:59         ` Kim F. Storm
2002-05-16  1:26           ` Miles Bader
2002-05-16 22:26             ` Kim F. Storm
2002-05-16 21:38               ` Stefan Monnier
2002-05-17 11:59                 ` Kai Großjohann
2002-05-18 18:48                 ` Richard Stallman
2002-05-18 22:24                   ` Stefan Monnier
2002-05-19 12:02                     ` Kai Großjohann
2002-05-19 14:50                       ` Eli Zaretskii
2002-05-19 15:23                         ` Kai Großjohann
2002-05-19 19:40                     ` Richard Stallman
2002-05-19 23:33                       ` Kim F. Storm
2002-05-20  9:50                         ` Alex Schroeder
2002-05-16 21:58               ` Miles Bader
2002-05-17 12:01                 ` Kai Großjohann
2002-05-17 21:56                 ` Kim F. Storm
2002-05-18  6:31                   ` Eli Zaretskii
2002-05-18 22:47                   ` Stefan Monnier
2002-05-17  6:15               ` Eli Zaretskii
2002-05-17 11:58               ` Kai Großjohann
2002-05-16  4:54           ` Eli Zaretskii
2002-05-16 22:10             ` Kim F. Storm
2002-05-16 21:20               ` Miles Bader
2002-05-17  6:13                 ` Eli Zaretskii
2002-05-18 18:49             ` Richard Stallman
2002-05-19  4:51               ` Eli Zaretskii
2002-05-19 19:40                 ` Richard Stallman
2002-05-19 23:29                 ` Kim F. Storm
2002-05-20  3:31                   ` Eli Zaretskii
2002-05-16 20:24         ` Richard Stallman
2002-05-15 21:55       ` Kim F. Storm
2002-05-16  4:52         ` Eli Zaretskii
     [not found]           ` <5xbsbf4thx.fsf@kfs2.cua.dk>
2002-05-17  6:22             ` Eli Zaretskii
2002-05-12 10:06 ` Kai Großjohann
2002-05-12 17:03   ` Alex Schroeder
2002-05-13 19:26     ` Kim F. Storm
2002-05-14  5:26       ` Miles Bader
2002-05-16 11:04 ` Kai Großjohann
2002-05-16 12:30   ` Eli Zaretskii
2002-05-16 13:05   ` D. Goel
2002-05-16 22:37   ` Alex Schroeder
2002-05-16 22:44   ` Kim F. Storm
2002-05-17 19:28   ` Richard Stallman
2002-05-18  6:26     ` Eli Zaretskii
2002-05-19  5:30       ` Richard Stallman
2002-05-23 21:41 ` Kim F. Storm

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.