all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Miles Bader <miles@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: bug#7234: 24.0.50; strange message after text-scale-adjust
Date: Mon, 18 Oct 2010 10:17:53 -0400	[thread overview]
Message-ID: <jwv62wzy4nf.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <87mxqbu1ii.fsf@catnip.gol.com> (Miles Bader's message of "Mon, 18 Oct 2010 21:30:13 +0900")

> 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)))
  
  \f
  ;; ----------------------------------------------------------------
--- 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))))
  
  \f
  ;; ----------------------------------------------------------------

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)))



  reply	other threads:[~2010-10-18 14:17 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-18  4:09 bug#7234: 24.0.50; strange message after text-scale-adjust Kenichi Handa
2010-10-18  7:16 ` Eli Zaretskii
2010-10-18 10:55   ` Kenichi Handa
     [not found]   ` <mailman.0.1287400359.30531.bug-gnu-emacs@gnu.org>
2010-10-18 12:30     ` Miles Bader
2010-10-18 14:17       ` Stefan Monnier [this message]
2010-10-19  0:37         ` Kenichi Handa
2010-10-19 16:26           ` Stefan Monnier
2010-10-20  2:00             ` Kenichi Handa
2010-10-20 16:07               ` Stefan Monnier
2010-10-21  1:21                 ` Kenichi Handa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwv62wzy4nf.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@gnu.org \
    --cc=miles@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.