From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.devel Subject: Re: binding c-h in isearch Date: Sat, 19 Apr 2008 23:07:07 +0300 Organization: JURTA Message-ID: <87fxthd8hk.fsf@jurta.org> References: <87d4oom6fm.fsf@jurta.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1208636232 18935 80.91.229.12 (19 Apr 2008 20:17:12 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 19 Apr 2008 20:17:12 +0000 (UTC) Cc: joakim@verona.se, emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Apr 19 22:17:45 2008 connect(): Connection refused Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1JnJVD-0001kp-Sd for ged-emacs-devel@m.gmane.org; Sat, 19 Apr 2008 22:17:40 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JnJUY-0006GA-4l for ged-emacs-devel@m.gmane.org; Sat, 19 Apr 2008 16:16:58 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JnJUT-0006Fa-Gt for emacs-devel@gnu.org; Sat, 19 Apr 2008 16:16:53 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JnJUS-0006FA-Ph for emacs-devel@gnu.org; Sat, 19 Apr 2008 16:16:53 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JnJUS-0006F7-Hh for emacs-devel@gnu.org; Sat, 19 Apr 2008 16:16:52 -0400 Original-Received: from relay03.kiev.sovam.com ([62.64.120.201]) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1JnJUS-0005jh-59 for emacs-devel@gnu.org; Sat, 19 Apr 2008 16:16:52 -0400 Original-Received: from [83.170.232.243] (helo=smtp.svitonline.com) by relay03.kiev.sovam.com with esmtp (Exim 4.67) (envelope-from ) id 1JnJUN-000Gnr-L8; Sat, 19 Apr 2008 23:16:48 +0300 In-Reply-To: (Stefan Monnier's message of "Thu, 17 Apr 2008 20:42:33 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (x86_64-pc-linux-gnu) X-Scanner-Signature: 71e6baab755496ce2e629015b40026f0 X-DrWeb-checked: yes X-SpamTest-Envelope-From: juri@jurta.org X-SpamTest-Group-ID: 00000000 X-SpamTest-Header: Not Detected X-SpamTest-Info: Profiles 2676 [Apr 18 2008] X-SpamTest-Info: helo_type=3 X-SpamTest-Info: {HEADERS: header Content-Type found without required header Content-Transfer-Encoding} X-SpamTest-Method: none X-SpamTest-Rate: 10 X-SpamTest-Status: Not detected X-SpamTest-Status-Extended: not_detected X-SpamTest-Version: SMTP-Filter Version 3.0.0 [0255], KAS30/Release X-detected-kernel: by monty-python.gnu.org: FreeBSD 6.x (1) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:95468 Archived-At: >> I think a good binding for C-h in isearch-mode would be the following: > >> (define-key isearch-mode-map "\C-h" help-map) > >> I gives what Richard wants since it uses the global definition of C-h, >> and still it is intuitive to use just like its global definition when >> a minor mode is active: > >> C-h m describes the isearch mode among other minor modes, > > Sounds good, indeed. > > Could we tweak this so it gives an info closer to what > isearch-help-mode gives? I.e. move the info from isearch-forward's > docstring to isearch-mode's docstring, and tweak C-h m so that > isearch-mode's info comes first. I think it is useful to leave the full info on `isearch-forward' to be helpful for `C-h k C-s' to get the full info about isearch. But as Johan pointed out there are other problems with this approach. I wrote a patch that cures all there problems by using the proper treatment of help commands in isearch mode. It uses `make-help-screen' to create isearch specific help screen, creates a new map `isearch-help-map' and binds all characters to `isearch-other-control-char' (exactly as `isearch-mode-map' binds all characters to this command before redefining some of them in isearch mode). This fixes the problem Johan reported, so any character not redefined will be passed to `isearch-other-control-char' to treat it normally and to exit isearch before invoking its global help command. Also I noticed another problem: when `same-window-buffer-names' or `same-window-regexps' is redefined to display the *Help* buffer in the same window, it makes impossible to continue using isearch in the current window because it continues operating on the *Help* buffer in the same window. So it is necessary to bind `same-window-buffer-names' and `same-window-regexps' to nil temporarily to force displaying the Help buffer in another window. All these changes provide the following new behavior: in isearch mode to get isearch specific help, the user types `C-h' and sees the message: C-h (Type ? for further options)- After typing `?' or `C-h' or `f1', the user sees the full help screen with most important isearch help commands: `b', `k' and `m'. (`c' is useless because the "I-search: " prompt overwrites the single line displayed in the echo area by `describe-key-briefly') These three help commands are important in isearch mode, because it is impossible to easily get their information outside isearch mode using global help commands. All the rest global help commands are not isearch specific, so e.g. `C-h f isearch-forward' gives the same info in isearch mode as well as globally. In isearch mode, these global help commands will exit isearch mode and invoke their global definitions, as Richard wants according to his comment in isearch.el. This patch also removes the full list of all isearch commands from the docstring of `isearch-mode' because most other modes don't have such a list in their docstrings, and anyway this list is now available via `C-h b'. (Also it leaves a single sentence on its docstring, and prepends the word "function" before the reference to `isearch-forward' in the docstring to force this link to lead to the definition of the function, not the variable). Index: lisp/isearch.el =================================================================== RCS file: /sources/emacs/emacs/lisp/isearch.el,v retrieving revision 1.316 diff -c -r1.316 isearch.el *** lisp/isearch.el 18 Apr 2008 10:29:23 -0000 1.316 --- lisp/isearch.el 19 Apr 2008 20:04:05 -0000 *************** *** 322,327 **** --- 322,396 ---- 'lazy-highlight-face "22.1") + ;; Define isearch help map. + + (eval-when-compile (require 'help-macro)) + + (make-help-screen isearch-help-for-help-internal + "Type a help option: [bkm] or ?" + "You have typed %THIS-KEY%, the help character. Type a Help option: + \(Type \\\\[help-quit] to exit the Help command.) + + b Display all isearch key bindings. + k KEYS Display the full documentation for the isearch key sequence. + m Display documentation of isearch mode. + + You can't type here other help keys available in the global help map, + but outise of this help window when you type them in isearch mode, + they exit isearch mode before displaying global help." + isearch-help-map) + + (defvar isearch-help-map + (let ((i 0) + (map (make-sparse-keymap))) + (while (< i 256) + (define-key map (vector i) 'isearch-other-control-char) + (setq i (1+ i))) + (define-key map (char-to-string help-char) 'isearch-help-for-help) + (define-key map [help] 'isearch-help-for-help) + (define-key map [f1] 'isearch-help-for-help) + (define-key map "?" 'isearch-help-for-help) + (define-key map "b" 'isearch-describe-bindings) + (define-key map "k" 'isearch-describe-key) + (define-key map "m" 'isearch-describe-mode) + (define-key map "q" 'help-quit) + map) + "Keymap for characters following the Help key for isearch mode.") + + (defun isearch-help-for-help () + "Display isearch help menu." + (interactive) + (let (same-window-buffer-names same-window-regexps) + (isearch-help-for-help-internal)) + (isearch-update)) + + (defun isearch-describe-bindings () + "Show a list of all keys defined in isearch mode, and their definitions. + This is like `describe-bindings', but displays only isearch keys." + (interactive) + (let (same-window-buffer-names same-window-regexps) + (with-help-window "*Help*" + (with-current-buffer standard-output + (princ "Isearch Mode Bindings:\n") + (princ (substitute-command-keys "\\{isearch-mode-map}")))))) + + (defun isearch-describe-key () + "Display documentation of the function invoked by isearch key." + (interactive) + (let (same-window-buffer-names same-window-regexps) + (call-interactively 'describe-key)) + (isearch-update)) + + (defun isearch-describe-mode () + "Display documentation of isearch mode." + (interactive) + (let (same-window-buffer-names same-window-regexps) + (describe-function 'isearch-forward)) + (isearch-update)) + + (defalias 'isearch-mode-help 'isearch-describe-mode) + + ;; Define isearch-mode keymap. (defvar isearch-mode-map *************** *** 391,396 **** --- 460,466 ---- ;; Turned off because I find I expect to get the global definition--rms. ;; ;; Instead bind C-h to special help command for isearch-mode. ;; (define-key map "\C-h" 'isearch-mode-help) + (define-key map "\C-h" isearch-help-map) (define-key map "\M-n" 'isearch-ring-advance) (define-key map "\M-p" 'isearch-ring-retreat) *************** *** 575,580 **** --- 645,654 ---- ring. Type \\[isearch-complete] to complete the search string using the search ring. + Type \\[isearch-describe-bindings] to display all isearch key bindings. + Type \\[isearch-describe-key] to display documentation of isearch key. + Type \\[isearch-describe-mode] to display documentation of isearch mode. + If an input method is turned on in the current buffer, that input method is also active while you are typing characters to search. To toggle the input method, type \\[isearch-toggle-input-method]. It *************** *** 627,638 **** (interactive "P\np") (isearch-mode nil (null not-regexp) nil (not no-recursive-edit))) - - (defun isearch-mode-help () - (interactive) - (describe-function 'isearch-forward) - (isearch-update)) - ;; isearch-mode only sets up incremental search for the minor mode. ;; All the work is done by the isearch-mode commands. --- 701,706 ---- *************** *** 644,652 **** (defun isearch-mode (forward &optional regexp op-fun recursive-edit word-p) ! "Start isearch minor mode. Called by `isearch-forward', etc. ! ! \\{isearch-mode-map}" ;; Initialize global vars. (setq isearch-forward forward --- 712,719 ---- (defun isearch-mode (forward &optional regexp op-fun recursive-edit word-p) ! "Start isearch minor mode. ! It is called by the function `isearch-forward' and other related functions." ;; Initialize global vars. (setq isearch-forward forward -- Juri Linkov http://www.jurta.org/emacs/