all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: phillip.lord@newcastle.ac.uk (Phillip Lord)
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-devel@gnu.org
Subject: Re: pre-command-hook with input methods
Date: Wed, 27 May 2015 17:03:06 +0100	[thread overview]
Message-ID: <87617em2it.fsf@newcastle.ac.uk> (raw)
In-Reply-To: <jwv617gclvz.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Mon, 25 May 2015 18:52:10 -0400")



Had a bit of a nightmare building from trunk. I still do not understand
why this happens so inconsistently for me; my "main" clone failed to
build even after make bookstrap, but a clone of the clone worked fine. I
really must be doing something wrong thing.

Still I have tried adding this to pabbrev. The -off variable is just so I
test what I am seeing.

(defvar pabbrev-input-event-functions-off t)

(defun pabbrev-input-event-functions (_)
  (unless pabbrev-input-event-functions-off
    (condition-case err
        (when pabbrev-marker
          (pabbrev-delete-last-suggestion)))))

This appears to work. Using italian-postfix, with -off set to t in
scratch I get, after typing "bu" I get

b[u]u_

(where u_ is u underlined).

With it -off set to nil, I get

bu_

(i.e. a u waiting for the dead-key). At the moment, this also means that
it's never possible to complete after a "u" (or a "u`") or any character
with a dead key. That would require quite a lot more thought; I guess
that the "u" you can see on screen is not really in the buffer until the
command (and key sequence) has completed anyway. Still if someone really
cared about this, they could switch to a pre-fix method. I tried
french-prefix and that works nicely, although, even using Emacs, I still
can't actually speak French.

So, the practical upshot is, yes, it seems to work nicely!

Phil



Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> I think so yes -- so long as input-event means "user input-event" or I
>> have some way of telling. Something coming in from a process, or
>> file-watch notifications need to be ignored.
>
> Could you try the patch below to see if it provides the feature
> you need?
>
>
>         Stefan
>
>
> diff --git a/etc/NEWS b/etc/NEWS
> index 1cccc31..f1b7119 100644
> --- a/etc/NEWS
> +++ b/etc/NEWS
> @@ -811,6 +811,8 @@ behavior, set `diff-switches' to `-c'.
>  \f
>  * Lisp Changes in Emacs 25.1
>  
> +** New hook `input-event-functions' run whenever a user-input event is read.
> +
>  ** The default value of `load-read-function' is now `read'.
>  
>  ** New hook `pre-redisplay-functions', a bit easier to use than pre-redisplay-function.
> diff --git a/lisp/subr.el b/lisp/subr.el
> index b9a847d..df0ed42 100644
> --- a/lisp/subr.el
> +++ b/lisp/subr.el
> @@ -1110,6 +1110,12 @@ See `event-start' for a description of the value returned."
>    "Return the multi-click count of EVENT, a click or drag event.
>  The return value is a positive integer."
>    (if (and (consp event) (integerp (nth 2 event))) (nth 2 event) 1))
> +
> +(defvar input-event-functions nil
> +  ;; BEWARE: If it looks like this is not run anywhere, it's normal:
> +  ;; this is run in keyboard.c.
> +  "Special hook run each time a user-input event is read.
> +Each function is called with one argument: the event.")
>  \f
>  ;;;; Extracting fields of the positions in an event.
>  
> diff --git a/src/keyboard.c b/src/keyboard.c
> index eb66c44..5c64199 100644
> --- a/src/keyboard.c
> +++ b/src/keyboard.c
> @@ -2454,7 +2454,7 @@ read_char (int commandflag, Lisp_Object map,
>  	  /* Also check was_disabled so last-nonmenu-event won't return
>  	     a bad value when submenus are involved.  (Bug#447)  */
>  	  && (EQ (c, Qtool_bar) || EQ (c, Qmenu_bar) || was_disabled))
> -	*used_mouse_menu = 1;
> +	*used_mouse_menu = true;
>  
>        goto reread_for_input_method;
>      }
> @@ -2995,6 +2995,8 @@ read_char (int commandflag, Lisp_Object map,
>    if (! NILP (also_record))
>      record_char (also_record);
>  
> +  Frun_hook_with_args (2, ((Lisp_Object []) {Qinput_event_functions, c}));
> +
>    /* Wipe the echo area.
>       But first, if we are about to use an input method,
>       save the echo area contents for it to refer to.  */
> @@ -3986,7 +3988,7 @@ kbd_buffer_get_event (KBOARD **kbp,
>              obj = list1 (intern ("ns-unput-working-text"));
>  	  kbd_fetch_ptr = event + 1;
>            if (used_mouse_menu)
> -            *used_mouse_menu = 1;
> +            *used_mouse_menu = true;
>          }
>  #endif
>  
> @@ -4181,13 +4183,13 @@ kbd_buffer_get_event (KBOARD **kbp,
>  		  && !EQ (event->frame_or_window, event->arg)
>  		  && (event->kind == MENU_BAR_EVENT
>  		      || event->kind == TOOL_BAR_EVENT))
> -		*used_mouse_menu = 1;
> +		*used_mouse_menu = true;
>  #endif
>  #ifdef HAVE_NS
>  	      /* Certain system events are non-key events.  */
>  	      if (used_mouse_menu
>                    && event->kind == NS_NONKEY_EVENT)
> -		*used_mouse_menu = 1;
> +		*used_mouse_menu = true;
>  #endif
>  
>  	      /* Wipe out this event, to catch bugs.  */
> @@ -8445,7 +8447,7 @@ read_char_x_menu_prompt (Lisp_Object map,
>  			 Lisp_Object prev_event, bool *used_mouse_menu)
>  {
>    if (used_mouse_menu)
> -    *used_mouse_menu = 0;
> +    *used_mouse_menu = false;
>  
>    /* Use local over global Menu maps.  */
>  
> @@ -8494,7 +8496,7 @@ read_char_x_menu_prompt (Lisp_Object map,
>        else if (NILP (value))
>  	value = Qt;
>        if (used_mouse_menu)
> -	*used_mouse_menu = 1;
> +	*used_mouse_menu = true;
>        return value;
>      }
>    return Qnil ;
> @@ -9067,7 +9069,7 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt,
>  	 : (/* indec.start < t || fkey.start < t || */ keytran.start < t))
>      {
>        Lisp_Object key;
> -      bool used_mouse_menu = 0;
> +      bool used_mouse_menu = false;
>  
>        /* Where the last real key started.  If we need to throw away a
>           key that has expanded into more than one element of keybuf
> @@ -11078,6 +11080,7 @@ syms_of_keyboard (void)
>    DEFSYM (Qself_insert_command, "self-insert-command");
>    DEFSYM (Qforward_char, "forward-char");
>    DEFSYM (Qbackward_char, "backward-char");
> +  DEFSYM (Qinput_event_functions, "input-event-functions");
>  
>    /* Non-nil disable property on a command means do not execute it;
>       call disabled-command-function's value instead.  */



  reply	other threads:[~2015-05-27 16:03 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-05 13:28 pre-command-hook with input methods Phillip Lord
2015-02-05 20:19 ` Stefan Monnier
2015-02-06 13:55   ` Phillip Lord
2015-02-06 15:17     ` Stefan Monnier
2015-02-06 15:45       ` Phillip Lord
2015-02-06 23:58         ` Stefan Monnier
2015-02-09 10:47           ` Phillip Lord
2015-02-09 14:41             ` Stefan Monnier
2015-02-09 15:30               ` Phillip Lord
2015-02-09 16:13                 ` Stefan Monnier
2015-02-10 14:09                   ` Phillip Lord
2015-02-11 17:17                     ` Phillip Lord
2015-02-11 19:21                       ` Stefan Monnier
2015-02-12 10:27                         ` Phillip Lord
2015-05-25 22:52                     ` Stefan Monnier
2015-05-27 16:03                       ` Phillip Lord [this message]
2015-05-27 19:45                         ` Stefan Monnier
2015-05-27 21:54                           ` Phillip Lord

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=87617em2it.fsf@newcastle.ac.uk \
    --to=phillip.lord@newcastle.ac.uk \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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.