From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: bug#7234: 24.0.50; strange message after text-scale-adjust Date: Mon, 18 Oct 2010 10:17:53 -0400 Message-ID: References: <87mxqbu1ii.fsf@catnip.gol.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1287411490 25909 80.91.229.12 (18 Oct 2010 14:18:10 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 18 Oct 2010 14:18:10 +0000 (UTC) Cc: emacs-devel@gnu.org To: Miles Bader Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Oct 18 16:18:08 2010 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.69) (envelope-from ) id 1P7qXN-0004hB-1H for ged-emacs-devel@m.gmane.org; Mon, 18 Oct 2010 16:18:05 +0200 Original-Received: from localhost ([127.0.0.1]:34446 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P7qXL-0006Oo-K5 for ged-emacs-devel@m.gmane.org; Mon, 18 Oct 2010 10:18:03 -0400 Original-Received: from [140.186.70.92] (port=35267 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P7qXE-0006MR-47 for emacs-devel@gnu.org; Mon, 18 Oct 2010 10:17:57 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P7qXD-00059U-04 for emacs-devel@gnu.org; Mon, 18 Oct 2010 10:17:56 -0400 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.183]:23883 helo=ironport2-out.pppoe.ca) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P7qXC-00059B-Sa; Mon, 18 Oct 2010 10:17:54 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ag4JALvzu0xMCpO7/2dsb2JhbACgM3lyviOFSQSSGQ X-IronPort-AV: E=Sophos;i="4.57,345,1283745600"; d="scan'208";a="80005735" Original-Received: from 76-10-147-187.dsl.teksavvy.com (HELO pastel.home) ([76.10.147.187]) by ironport2-out.pppoe.ca with ESMTP/TLS/ADH-AES256-SHA; 18 Oct 2010 10:17:53 -0400 Original-Received: by pastel.home (Postfix, from userid 20848) id 0F91CA8219; Mon, 18 Oct 2010 10:17:53 -0400 (EDT) In-Reply-To: <87mxqbu1ii.fsf@catnip.gol.com> (Miles Bader's message of "Mon, 18 Oct 2010 21:30:13 +0900") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. 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:131806 Archived-At: > It would be better that read-event call in > text-scale-adjust has some prompt: > e.g. (read-event "+,-,0 for further adjustment: ") Agreed. > For non-interactive use, you should probably also be using > `text-scale-set' or `text-scale-increase' instead. BTW, I've been playing around with an alternative implementation for such things. The reason is that the use of read-event/read-char/read-key has surprising side-effects: in those cases I'm concerned with, the user expects that the command is already finished and the behavior is somewhat consistent with that expectation, but not completely: indeed typing "any" key sequence (except for a few special ones) runs the usual corresponding command, but OTOH post-command-hook and friends aren't run when expected. So, instead I use a new function set-temporary-overlay-map which sets up a keymap that's only active for a short period of time (by default just for the next key-sequence): Using submit branch file:///home/monnier/src/emacs/bzr/trunk/ === modified file 'lisp/face-remap.el' *** lisp/face-remap.el 2010-03-14 21:15:02 +0000 --- lisp/face-remap.el 2010-08-21 07:43:23 +0000 *************** *** 294,319 **** `text-scale-decrease' may be more appropriate." (interactive "p") (let ((first t) - (step t) (ev last-command-event) (echo-keystrokes nil)) ! (while step ! (let ((base (event-basic-type ev))) ! (cond ((or (eq base ?+) (eq base ?=)) ! (setq step inc)) ! ((eq base ?-) ! (setq step (- inc))) ! ((eq base ?0) ! (setq step 0)) ! (first ! (setq step inc)) ! (t ! (setq step nil)))) ! (when step (text-scale-increase step) ! (setq inc 1 first nil) ! (setq ev (read-event)))) ! (push ev unread-command-events))) ;; ---------------------------------------------------------------- --- 294,317 ---- `text-scale-decrease' may be more appropriate." (interactive "p") (let ((first t) (ev last-command-event) (echo-keystrokes nil)) ! (let* ((base (event-basic-type ev)) ! (step ! (case base ! ((?+ ?=) inc) ! (?- (- inc)) ! (?0 0) ! (t inc)))) (text-scale-increase step) ! (set-temporary-overlay-map ! (let ((map (make-sparse-keymap))) ! (define-key map [?=] 'text-scale-increase) ! (define-key map [?0] (lambda () (interactive) (text-scale-increase 0))) ! (define-key map [?+] 'text-scale-increase) ! (define-key map [?-] 'text-scale-decrease) ! map) ! t)))) ;; ---------------------------------------------------------------- Currently, my implementation of set-temporary-overlay-map (see appended) is not 100% satisfactory, so it may require some changes to the C code, but it already works well in practice. Stefan (defun set-temporary-overlay-map (map &optional keep-pred) (let* ((clearfunsym (make-symbol "clear-temporary-overlay-map")) (overlaysym (make-symbol "t")) (alist (list (cons overlaysym map))) (clearfun `(lambda () (unless ,(cond ((null keep-pred) nil) ((eq t keep-pred) `(eq this-command (lookup-key ',map (this-command-keys-vector)))) (t `(funcall ',keep-pred))) (remove-hook 'pre-command-hook ',clearfunsym) (cancel-timer ,overlaysym) (setq ,overlaysym nil) (save-current-buffer (if (buffer-live-p ',(current-buffer)) (set-buffer ',(current-buffer))) (setq emulation-mode-map-alists (delq ',alist emulation-mode-map-alists))))))) (fset clearfunsym clearfun) (add-hook 'pre-command-hook clearfunsym) ;; Sadly, pre-command-hook is occasionally set to nil (if one of its ;; functions signals an error). We should improve safe_run_hooks so as to ;; only remove the offending function rather than set the whole thing to ;; nil, but in the mean time, let's use an auxiliary timer to monitor ;; pre-command-hook to make sure we don't end up with a lingering ;; overlay-map which could otherwise render Emacs unusable. (set overlaysym (run-with-idle-timer 0 t `(lambda () (if (memq ',clearfunsym (default-value 'pre-command-hook)) nil (message "clear-temporary-overlay-map lost in pre-command-hook!") (,clearfunsym))))) ;; FIXME: That's the keymaps with highest precedence, except for ;; the `keymap' text-property ;-( (push alist emulation-mode-map-alists)))