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: Why is `C-x 8' limited to Latin-1 for search? Date: Mon, 10 Dec 2012 23:57:17 +0200 Organization: JURTA Message-ID: <87zk1lfu4j.fsf@mail.jurta.org> References: <1992681966EA4AE4A56751FA335DD5CE@us.oracle.com> <9A96D353A11D47A7A143074DB1E09EE4@us.oracle.com> <8738ze4jid.fsf@mail.jurta.org> <9CE95F039B2A4295BA1273CD98924B43@us.oracle.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1355177462 25021 80.91.229.3 (10 Dec 2012 22:11:02 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 10 Dec 2012 22:11:02 +0000 (UTC) Cc: emacs-devel@gnu.org To: "Drew Adams" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Dec 10 23:11:16 2012 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1TiBZD-0002VE-20 for ged-emacs-devel@m.gmane.org; Mon, 10 Dec 2012 23:11:15 +0100 Original-Received: from localhost ([::1]:35776 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TiBZ0-0005nZ-At for ged-emacs-devel@m.gmane.org; Mon, 10 Dec 2012 17:11:02 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:46749) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TiBYw-0005nT-Bk for emacs-devel@gnu.org; Mon, 10 Dec 2012 17:11:01 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TiBYu-00029J-UQ for emacs-devel@gnu.org; Mon, 10 Dec 2012 17:10:58 -0500 Original-Received: from ps18281.dreamhost.com ([69.163.218.105]:41037 helo=ps18281.dreamhostps.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TiBYu-000290-MC for emacs-devel@gnu.org; Mon, 10 Dec 2012 17:10:56 -0500 Original-Received: from localhost (ps18281.dreamhostps.com [69.163.218.105]) by ps18281.dreamhostps.com (Postfix) with ESMTP id C03C6451CD5D; Mon, 10 Dec 2012 14:10:54 -0800 (PST) In-Reply-To: <9CE95F039B2A4295BA1273CD98924B43@us.oracle.com> (Drew Adams's message of "Mon, 10 Dec 2012 06:24:24 -0800") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (x86_64-pc-linux-gnu) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] X-Received-From: 69.163.218.105 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:155441 Archived-At: > But I don't know what you mean by "except the part that changes > `isearch-new-string' and `isearch-new-message'. I do change both, to reflect > the added char. No doubt you had a slightly different macro in mind. I meant that `isearch-edit-string' does more than needed for the command that will read and insert an Unicode char. For example, currently it binds `history-add-new-input' to nil. This means that your code doesn't add the char name to the minibuffer's history. Executing any code in the macro's body will also allow doing more amazing things like temporarily going into a recursive edit with: (define-key isearch-mode-map "\M-r" (lambda () (interactive) (with-isearch-suspend (recursive-edit)))) where `C-M-c' will continue the suspended isearch. This will be possible to do with this patch: === modified file 'lisp/isearch.el' --- lisp/isearch.el 2012-11-21 10:32:38 +0000 +++ lisp/isearch.el 2012-12-10 21:57:00 +0000 @@ -534,7 +534,7 @@ (defvar isearch-mode-map (define-key map "\C-x" nil) (define-key map [?\C-x t] 'isearch-other-control-char) (define-key map "\C-x8" nil) - (define-key map "\C-x8\r" 'isearch-other-control-char) + (define-key map "\C-x8\r" 'isearch-insert-char-by-name) map) "Keymap for `isearch-mode'.") @@ -1140,23 +1140,17 @@ (defun isearch-fail-pos (&optional msg) (length succ-msg) 0)))) -(defun isearch-edit-string () - "Edit the search string in the minibuffer. -The following additional command keys are active while editing. -\\ -\\[exit-minibuffer] to resume incremental searching with the edited string. -\\[isearch-nonincremental-exit-minibuffer] to do one nonincremental search. -\\[isearch-forward-exit-minibuffer] to resume isearching forward. -\\[isearch-reverse-exit-minibuffer] to resume isearching backward. -\\[isearch-complete-edit] to complete the search string using the search ring." - +(defmacro with-isearch-suspend (&rest body) + "Exit Isearch mode, run BODY, and reinvoke the pending search. +You can update the global isearch variables by setting new values to +`isearch-new-string', `isearch-new-message', `isearch-new-forward', +`isearch-new-word', `isearch-new-case-fold'." ;; This code is very hairy for several reasons, explained in the code. ;; Mainly, isearch-mode must be terminated while editing and then restarted. ;; If there were a way to catch any change of buffer from the minibuffer, ;; this could be simplified greatly. ;; Editing doesn't back up the search point. Should it? - (interactive) - (condition-case nil + `(condition-case nil (progn (let ((isearch-nonincremental isearch-nonincremental) @@ -1219,29 +1213,7 @@ (defun isearch-edit-string () (setq old-point (point) old-other-end isearch-other-end) (unwind-protect - (let* ((message-log-max nil) - ;; Don't add a new search string to the search ring here - ;; in `read-from-minibuffer'. It should be added only - ;; by `isearch-update-ring' called from `isearch-done'. - (history-add-new-input nil) - ;; Binding minibuffer-history-symbol to nil is a work-around - ;; for some incompatibility with gmhist. - (minibuffer-history-symbol)) - (setq isearch-new-string - (read-from-minibuffer - (isearch-message-prefix nil isearch-nonincremental) - (cons isearch-string (1+ (or (isearch-fail-pos) - (length isearch-string)))) - minibuffer-local-isearch-map nil - (if isearch-regexp - (cons 'regexp-search-ring - (1+ (or regexp-search-ring-yank-pointer -1))) - (cons 'search-ring - (1+ (or search-ring-yank-pointer -1)))) - nil t) - isearch-new-message - (mapconcat 'isearch-text-char-description - isearch-new-string ""))) + (progn ,@body) ;; Set point at the start (end) of old match if forward (backward), ;; so after exiting minibuffer isearch resumes at the start (end) @@ -1300,6 +1272,41 @@ (defun isearch-edit-string () (isearch-abort) ;; outside of let to restore outside global values ))) +(defun isearch-edit-string () + "Edit the search string in the minibuffer. +The following additional command keys are active while editing. +\\ +\\[exit-minibuffer] to resume incremental searching with the edited string. +\\[isearch-nonincremental-exit-minibuffer] to do one nonincremental search. +\\[isearch-forward-exit-minibuffer] to resume isearching forward. +\\[isearch-reverse-exit-minibuffer] to resume isearching backward. +\\[isearch-complete-edit] to complete the search string using the search ring." + (interactive) + (with-isearch-suspend + (let* ((message-log-max nil) + ;; Don't add a new search string to the search ring here + ;; in `read-from-minibuffer'. It should be added only + ;; by `isearch-update-ring' called from `isearch-done'. + (history-add-new-input nil) + ;; Binding minibuffer-history-symbol to nil is a work-around + ;; for some incompatibility with gmhist. + (minibuffer-history-symbol)) + (setq isearch-new-string + (read-from-minibuffer + (isearch-message-prefix nil isearch-nonincremental) + (cons isearch-string (1+ (or (isearch-fail-pos) + (length isearch-string)))) + minibuffer-local-isearch-map nil + (if isearch-regexp + (cons 'regexp-search-ring + (1+ (or regexp-search-ring-yank-pointer -1))) + (cons 'search-ring + (1+ (or search-ring-yank-pointer -1)))) + nil t) + isearch-new-message + (mapconcat 'isearch-text-char-description + isearch-new-string ""))))) + (defun isearch-nonincremental-exit-minibuffer () (interactive) (setq isearch-nonincremental t) @@ -1870,6 +1877,17 @@ (defun isearch-yank-line () (lambda () (let ((inhibit-field-text-motion t)) (line-end-position (if (eolp) 2 1)))))) +(defun isearch-insert-char-by-name () + "Read a character by its Unicode name and insert it into search string." + (interactive) + (with-isearch-suspend + (let ((char (read-char-by-name "Insert character (Unicode name or hex): "))) + (when char + (setq isearch-new-string (concat isearch-string (string char)) + isearch-new-message (concat isearch-message + (mapconcat 'isearch-text-char-description + (string char) ""))))))) + (defun isearch-search-and-update () ;; Do the search and update the display. (when (or isearch-success