all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: David Kastrup <dak@gnu.org>
Cc: cyd@stupidchicken.com, emacs-devel@gnu.org, storm@cua.dk
Subject: Re: local keymap patch for key-binding
Date: Sat, 16 Sep 2006 01:47:58 +0200	[thread overview]
Message-ID: <853bas3d5d.fsf@lola.goethe.zz> (raw)
In-Reply-To: <85r6yeek4e.fsf@lola.goethe.zz> (David Kastrup's message of "Thu\, 14 Sep 2006 13\:57\:21 +0200")

[-- Attachment #1: Type: text/plain, Size: 1586 bytes --]

David Kastrup <dak@gnu.org> writes:

> Richard Stallman <rms@gnu.org> writes:
>
>> Ok, I agree to adding the LOCATION arg.  But it needs to be documented.
>
> Here is the latest patch iteration.  I think it should be fit for
> checking in.  It might also seem reasonable to add the optional
> `position' argument to `current-active-maps', but this has not been
> done.

Here is a patch that would achieve that.  After scanning through
keymap.c, I believe that this should be the last change required to
provide APIs to the keymap access on overlays and display strings,
thus making manual simulation of keymap search order for whatever
purpose unnecessary.  At a cursory glance through callers, I don't see
code within Emacs itself which would really require this at the
current point of time.  I remember some stuff by now implemented with
unread-command-events that went through hoops in order to repeat a key
lookup with one keymap excluded.

This kind of thing would be more reliably achieved by using
`current-active-maps' with a position argument, removing the
non-needed keymap from the list, and repeating the lookup.

While I don't think we should change any of the existing callers right
now, it might be a good idea to have this API available in future.
The implementation is reasonably simple.  I don't think a GCPRO is
needed here, but I can't say that I know garbage collection inside
out.

If there is agreement to put this in in order to complete the accessor
functions to mouse-dependent keymaps, I would add this to the manual
and NEWS file, too.

What do you think?


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-patch, Size: 8661 bytes --]

Index: src/keymap.h
===================================================================
RCS file: /sources/emacs/emacs/src/keymap.h,v
retrieving revision 1.15
diff -u -r1.15 keymap.h
*** src/keymap.h	15 Sep 2006 07:19:14 -0000	1.15
--- src/keymap.h	15 Sep 2006 23:46:07 -0000
***************
*** 34,40 ****
  EXFUN (Fkey_description, 2);
  EXFUN (Fsingle_key_description, 2);
  EXFUN (Fwhere_is_internal, 5);
! EXFUN (Fcurrent_active_maps, 1);
  extern Lisp_Object access_keymap P_ ((Lisp_Object, Lisp_Object, int, int, int));
  extern Lisp_Object get_keyelt P_ ((Lisp_Object, int));
  extern Lisp_Object get_keymap P_ ((Lisp_Object, int, int));
--- 34,40 ----
  EXFUN (Fkey_description, 2);
  EXFUN (Fsingle_key_description, 2);
  EXFUN (Fwhere_is_internal, 5);
! EXFUN (Fcurrent_active_maps, 2);
  extern Lisp_Object access_keymap P_ ((Lisp_Object, Lisp_Object, int, int, int));
  extern Lisp_Object get_keyelt P_ ((Lisp_Object, int));
  extern Lisp_Object get_keymap P_ ((Lisp_Object, int, int));
Index: src/keymap.c
===================================================================
RCS file: /sources/emacs/emacs/src/keymap.c,v
retrieving revision 1.334
diff -u -r1.334 keymap.c
*** src/keymap.c	15 Sep 2006 07:19:14 -0000	1.334
--- src/keymap.c	15 Sep 2006 23:46:10 -0000
***************
*** 1510,1523 ****
  }
  
  DEFUN ("current-active-maps", Fcurrent_active_maps, Scurrent_active_maps,
!        0, 1, 0,
         doc: /* Return a list of the currently active keymaps.
  OLP if non-nil indicates that we should obey `overriding-local-map' and
! `overriding-terminal-local-map'.  */)
!      (olp)
!      Lisp_Object olp;
  {
!   Lisp_Object keymaps = Fcons (current_global_map, Qnil);
  
    if (!NILP (olp))
      {
--- 1510,1556 ----
  }
  
  DEFUN ("current-active-maps", Fcurrent_active_maps, Scurrent_active_maps,
!        0, 2, 0,
         doc: /* Return a list of the currently active keymaps.
  OLP if non-nil indicates that we should obey `overriding-local-map' and
! `overriding-terminal-local-map'.  POSITION can specify a click position
! like in the respective argument of `key-binding'. */)
!     (olp, position)
!     Lisp_Object olp, position;
  {
!   int count = SPECPDL_INDEX ();
! 
!   Lisp_Object keymaps;
! 
!   /* If a mouse click position is given, our variables are based on
!      the buffer clicked on, not the current buffer.  So we may have to
!      switch the buffer here. */
!   
!   if (CONSP (position))
!     {
!       Lisp_Object window;
!       
!       window = POSN_WINDOW (position);
! 	  
!       if (WINDOWP (window)
! 	  && BUFFERP (XWINDOW (window)->buffer)
! 	  && XBUFFER (XWINDOW (window)->buffer) != current_buffer)
! 	{
! 	  /* Arrange to go back to the original buffer once we're done
! 	     processing the key sequence.  We don't use
! 	     save_excursion_{save,restore} here, in analogy to
! 	     `read-key-sequence' to avoid saving point.  Maybe this
! 	     would not be a problem here, but it is easier to keep
! 	     things the same.
! 	  */
! 	      
! 	  record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
! 	  
! 	  set_buffer_internal (XBUFFER (XWINDOW (window)->buffer));
! 	}
!     }
! 
!   keymaps = Fcons (current_global_map, Qnil);  
  
    if (!NILP (olp))
      {
***************
*** 1531,1545 ****
      }
    if (NILP (XCDR (keymaps)))
      {
-       Lisp_Object local;
        Lisp_Object *maps;
        int nmaps, i;
  
!       /* This usually returns the buffer's local map,
! 	 but that can be overridden by a `local-map' property.  */
!       local = get_local_map (PT, current_buffer, Qlocal_map);
!       if (!NILP (local))
! 	keymaps = Fcons (local, keymaps);
  
        /* Now put all the minor mode keymaps on the list.  */
        nmaps = current_minor_maps (0, &maps);
--- 1564,1640 ----
      }
    if (NILP (XCDR (keymaps)))
      {
        Lisp_Object *maps;
        int nmaps, i;
  
!       Lisp_Object keymap, local_map;
!       EMACS_INT pt;
! 
!       pt = INTEGERP (position) ? XINT (position)
! 	: MARKERP (position) ? marker_position (position)
! 	: PT;
! 
!       /* Get the buffer local maps, possibly overriden by text or
! 	 overlay properties */
! 
!       local_map = get_local_map (pt, current_buffer, Qlocal_map); 
!       keymap = get_local_map (pt, current_buffer, Qkeymap); 
! 
!       if (CONSP (position))
! 	{
! 	  Lisp_Object string, window;
! 
! 	  window = POSN_WINDOW (position);
! 
! 	  /* For a mouse click, get the local text-property keymap
! 	     of the place clicked on, rather than point.  */
! 	  
! 	  if (POSN_INBUFFER_P (position))
! 	    {
! 	      Lisp_Object pos;
! 
! 	      pos = POSN_BUFFER_POSN (position);
! 	      if (INTEGERP (pos)
! 		  && XINT (pos) >= BEG && XINT (pos) <= Z)
! 		{
! 		  local_map = get_local_map (XINT (pos),
! 					     current_buffer, Qlocal_map);
! 		  
! 		  keymap = get_local_map (XINT (pos),
! 					  current_buffer, Qkeymap);
! 		}
! 	    }
! 
! 	  /* If on a mode line string with a local keymap,
! 	     or for a click on a string, i.e. overlay string or a
! 	     string displayed via the `display' property,
! 	     consider `local-map' and `keymap' properties of
! 	     that string.  */
! 	  
! 	  if (string = POSN_STRING (position),
! 	      (CONSP (string) && STRINGP (XCAR (string))))
! 	    {
! 	      Lisp_Object pos, map;
! 	      
! 	      pos = XCDR (string);
! 	      string = XCAR (string);
! 	      if (XINT (pos) >= 0
! 		  && XINT (pos) < SCHARS (string))
! 		{
! 		  map = Fget_text_property (pos, Qlocal_map, string);
! 		  if (!NILP (map))
! 		    local_map = map;
! 
! 		  map = Fget_text_property (pos, Qkeymap, string);
! 		  if (!NILP (map))
! 		    keymap = map;
! 		}
! 	    }
! 	  
! 	}
! 
!       if (!NILP (local_map))
! 	keymaps = Fcons (local_map, keymaps);
  
        /* Now put all the minor mode keymaps on the list.  */
        nmaps = current_minor_maps (0, &maps);
***************
*** 1548,1559 ****
  	if (!NILP (maps[i]))
  	  keymaps = Fcons (maps[i], keymaps);
  
!       /* This returns nil unless there is a `keymap' property.  */
!       local = get_local_map (PT, current_buffer, Qkeymap);
!       if (!NILP (local))
! 	keymaps = Fcons (local, keymaps);
      }
  
    return keymaps;
  }
  
--- 1643,1654 ----
  	if (!NILP (maps[i]))
  	  keymaps = Fcons (maps[i], keymaps);
  
!       if (!NILP (keymap))
! 	keymaps = Fcons (keymap, keymaps);
      }
  
+   unbind_to (count, Qnil);
+ 
    return keymaps;
  }
  
***************
*** 2805,2811 ****
    else if (!NILP (keymap))
      keymaps = Fcons (keymap, Fcons (current_global_map, Qnil));
    else
!     keymaps = Fcurrent_active_maps (Qnil);
  
    /* Only use caching for the menubar (i.e. called with (def nil t nil).
       We don't really need to check `keymap'.  */
--- 2900,2906 ----
    else if (!NILP (keymap))
      keymaps = Fcons (keymap, Fcons (current_global_map, Qnil));
    else
!     keymaps = Fcurrent_active_maps (Qnil, Qnil);
  
    /* Only use caching for the menubar (i.e. called with (def nil t nil).
       We don't really need to check `keymap'.  */
Index: src/doc.c
===================================================================
RCS file: /sources/emacs/emacs/src/doc.c,v
retrieving revision 1.120
diff -u -r1.120 doc.c
*** src/doc.c	18 Jul 2006 13:26:24 -0000	1.120
--- src/doc.c	15 Sep 2006 23:46:12 -0000
***************
*** 883,889 ****
  	  struct buffer *oldbuf;
  	  int start_idx;
  	  /* This is for computing the SHADOWS arg for describe_map_tree.  */
! 	  Lisp_Object active_maps = Fcurrent_active_maps (Qnil);
  	  Lisp_Object earlier_maps;
  
  	  changed = 1;
--- 883,889 ----
  	  struct buffer *oldbuf;
  	  int start_idx;
  	  /* This is for computing the SHADOWS arg for describe_map_tree.  */
! 	  Lisp_Object active_maps = Fcurrent_active_maps (Qnil, Qnil);
  	  Lisp_Object earlier_maps;
  
  	  changed = 1;
Index: src/ChangeLog
===================================================================
RCS file: /sources/emacs/emacs/src/ChangeLog,v
retrieving revision 1.5302
diff -u -r1.5302 ChangeLog
*** src/ChangeLog	15 Sep 2006 21:01:03 -0000	1.5302
--- src/ChangeLog	15 Sep 2006 23:46:40 -0000
***************
*** 1,3 ****
--- 1,14 ----
+ 2006-09-16  David Kastrup  <dak@gnu.org>
+ 
+ 	* keymap.c (Fcurrent_active_maps): Add `position' argument.
+ 	(Fwhere_is_internal): Adjust call to `current-active-maps' to
+ 	cater for additional parameter.
+ 
+ 	* keymap.h: Adjust number of parameters to `current-active-maps'.
+ 
+ 	* doc.c (Fsubstitute_command_keys): Adjust call of
+ 	`current-active-maps'.
+ 
  2006-09-15  Kim F. Storm  <storm@cua.dk>
  
  	* window.c (Fwindow_line_visibility): New defun for line-move-partial.

[-- Attachment #3: Type: text/plain, Size: 52 bytes --]



-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum

[-- Attachment #4: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

  parent reply	other threads:[~2006-09-15 23:47 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-10  9:34 longlines-mode doesn't seem to work with some non-english text Miles Bader
2006-02-11  4:35 ` Chong Yidong
2006-02-13  0:32   ` Kevin Ryde
2006-09-09 15:08 ` local keymap patch for key-binding Chong Yidong
2006-09-09 15:15   ` David Kastrup
2006-09-09 15:26     ` Chong Yidong
2006-09-10 12:44     ` Chong Yidong
2006-09-10 13:25       ` David Kastrup
2006-09-11  2:36         ` Chong Yidong
2006-09-11  6:25           ` David Kastrup
2006-09-11  7:05           ` David Kastrup
2006-09-11  8:52             ` Kim F. Storm
2006-09-11  9:48               ` David Kastrup
2006-09-11 10:11                 ` David Kastrup
2006-09-11 12:53                   ` Kim F. Storm
2006-09-11 13:04                     ` David Kastrup
2006-09-11 13:07                   ` Chong Yidong
2006-09-11 19:58                 ` Richard Stallman
2006-09-12 10:04                   ` David Kastrup
2006-09-12 15:21                     ` David Kastrup
2006-09-12 15:39                       ` PCL-CVS's diff and marks (was: local keymap patch for key-binding) Stefan Monnier
2006-09-12 15:42                         ` PCL-CVS's diff and marks David Kastrup
2006-09-12 15:54                           ` Stefan Monnier
2006-09-12 21:45                       ` local keymap patch for key-binding Richard Stallman
2006-09-12 22:23                         ` David Kastrup
2006-09-12 23:44                           ` David Kastrup
2006-09-13  7:45                             ` Kim F. Storm
2006-09-13  8:11                               ` David Kastrup
2006-09-13 11:05                                 ` Kim F. Storm
2006-09-13 11:38                                   ` David Kastrup
2006-09-13 12:23                                     ` Kim F. Storm
2006-09-13 12:32                                       ` David Kastrup
2006-09-13 13:45                                         ` Kim F. Storm
2006-09-13 19:25                                     ` Richard Stallman
2006-09-13 19:49                                       ` David Kastrup
2006-09-13 19:25                                 ` Richard Stallman
2006-09-13 20:02                                   ` David Kastrup
2006-09-13 19:24                           ` Richard Stallman
2006-09-13 15:10                       ` Richard Stallman
2006-09-13 15:25                         ` David Kastrup
2006-09-14  2:34                           ` Richard Stallman
2006-09-14 11:57                             ` David Kastrup
2006-09-14 22:34                               ` David Kastrup
2006-09-14 22:36                                 ` David Kastrup
2006-09-15  3:14                               ` Richard Stallman
2006-09-15  8:20                                 ` David Kastrup
2006-09-15 23:47                               ` David Kastrup [this message]
2006-09-16  0:14                                 ` Kim F. Storm
2006-09-16 19:05                                   ` Richard Stallman
2006-09-18 15:43                                     ` David Kastrup
2006-09-18 20:34                                       ` Kim F. Storm
2006-09-18 23:39                                       ` Richard Stallman
2006-09-16 16:41                                 ` Stefan Monnier
2006-09-10 18:52       ` Richard Stallman
2006-09-11  2:39         ` Chong Yidong

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=853bas3d5d.fsf@lola.goethe.zz \
    --to=dak@gnu.org \
    --cc=cyd@stupidchicken.com \
    --cc=emacs-devel@gnu.org \
    --cc=storm@cua.dk \
    /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.