all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Overriding self-insert-command doesn't work
@ 2007-03-10 16:56 spamfilteraccount
  2007-03-12 17:23 ` Robert Thorpe
  0 siblings, 1 reply; 7+ messages in thread
From: spamfilteraccount @ 2007-03-10 16:56 UTC (permalink / raw)
  To: help-gnu-emacs

I'd like to override self-insert-command in a way that I replace the
actual function belonging to the symbol `self-insert-command'.

In the code below I do that. I store the old function definition,
replace it with my own definition and call the original definition
from my own function:


(defvar oldfunc (symbol-function 'self-insert-command))

(defun my-self-insert (n)
  "doc"
  (interactive "p")
  (funcall oldfunc n)
  (message "hello"))

(fset 'self-insert-command 'my-self-insert)


This solution doesn't work because it seems to affect only self-insert-
command function calls (hello is printed when I press enter which
presumably calls self-insert-command), but it's not printed when I
press any other self insert key (like "a"). Curiously, if I press "C-h
k a" then it says that "a" invokes my function, but it doesn't. Why is
that?

I tested it with Gnu Emacs 21.

I know about advising, so please don't recommend other ways to
accomplish this. I'd like to know why this specific solution doesn't
work.

Thanks.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Overriding self-insert-command doesn't work
  2007-03-10 16:56 Overriding self-insert-command doesn't work spamfilteraccount
@ 2007-03-12 17:23 ` Robert Thorpe
  2007-03-12 18:30   ` spamfilteraccount
  0 siblings, 1 reply; 7+ messages in thread
From: Robert Thorpe @ 2007-03-12 17:23 UTC (permalink / raw)
  To: help-gnu-emacs

On Mar 10, 4:56 pm, "spamfilteracco...@gmail.com"
<spamfilteracco...@gmail.com> wrote:
> I'd like to override self-insert-command in a way that I replace the
> actual function belonging to the symbol `self-insert-command'.
>
> In the code below I do that. I store the old function definition,
> replace it with my own definition and call the original definition
> from my own function:
>
> (defvar oldfunc (symbol-function 'self-insert-command))
>
> (defun my-self-insert (n)
>   "doc"
>   (interactive "p")
>   (funcall oldfunc n)
>   (message "hello"))
>
> (fset 'self-insert-command 'my-self-insert)
>
> This solution doesn't work because it seems to affect only self-insert-
> command function calls (hello is printed when I press enter which
> presumably calls self-insert-command), but it's not printed when I
> press any other self insert key (like "a"). Curiously, if I press "C-h
> k a" then it says that "a" invokes my function, but it doesn't. Why is
> that?
>
> I tested it with Gnu Emacs 21.

The command "self-insert-command" is inbuilt to Emacs.  It is part of
the static binary executable and is called directly by other parts of
that executable.  Changing it cannot change this version.

> I know about advising, so please don't recommend other ways to
> accomplish this.

OK.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Overriding self-insert-command doesn't work
  2007-03-12 17:23 ` Robert Thorpe
@ 2007-03-12 18:30   ` spamfilteraccount
  2007-03-12 19:30     ` David Hansen
                       ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: spamfilteraccount @ 2007-03-12 18:30 UTC (permalink / raw)
  To: help-gnu-emacs

On Mar 12, 6:23 pm, "Robert Thorpe" <rtho...@realworldtech.com> wrote:
>
> The command "self-insert-command" is inbuilt to Emacs.  It is part of
> the static binary executable and is called directly by other parts of
> that executable.  Changing it cannot change this version.

That's not very nice, is it? Regardless of whether it's built-in,
implemented in C, it should behave as a proper lisp symbol. I don't
see why built-in functions should have to call the internal
implementation of self-insert-command directly rather than invoking
the function in the symbol's function slot.

Isn't it a bug?

> > I know about advising, so please don't recommend other ways to
> > accomplish this.
>
> OK.

I mean if you know ways other than advising to change the definition
of self-insert-command transpararently then I'm all ears.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Overriding self-insert-command doesn't work
  2007-03-12 18:30   ` spamfilteraccount
@ 2007-03-12 19:30     ` David Hansen
  2007-03-13  2:04       ` Drew Adams
  2007-03-13  1:25     ` Barry Margolin
  2007-03-14 14:17     ` Robert Thorpe
  2 siblings, 1 reply; 7+ messages in thread
From: David Hansen @ 2007-03-12 19:30 UTC (permalink / raw)
  To: help-gnu-emacs

On 12 Mar 2007 11:30:58 -0700 "spamfilteraccount@gmail.com" <spamfilteraccount@gmail.com> wrote:
>
> I mean if you know ways other than advising to change the definition
> of self-insert-command transpararently then I'm all ears.

I don't know what you wanna do but maybe:

(define-key map [remap self-insert-command] #'my-version-of-self-insert)

or add some function to `after-change-functions'.  The first one
requires emacs 22 (AFAIK).

David

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Overriding self-insert-command doesn't work
  2007-03-12 18:30   ` spamfilteraccount
  2007-03-12 19:30     ` David Hansen
@ 2007-03-13  1:25     ` Barry Margolin
  2007-03-14 14:17     ` Robert Thorpe
  2 siblings, 0 replies; 7+ messages in thread
From: Barry Margolin @ 2007-03-13  1:25 UTC (permalink / raw)
  To: help-gnu-emacs

In article <1173724258.067960.37960@s48g2000cws.googlegroups.com>,
 "spamfilteraccount@gmail.com" <spamfilteraccount@gmail.com> wrote:

> On Mar 12, 6:23 pm, "Robert Thorpe" <rtho...@realworldtech.com> wrote:
> >
> > The command "self-insert-command" is inbuilt to Emacs.  It is part of
> > the static binary executable and is called directly by other parts of
> > that executable.  Changing it cannot change this version.
> 
> That's not very nice, is it? Regardless of whether it's built-in,
> implemented in C, it should behave as a proper lisp symbol. I don't
> see why built-in functions should have to call the internal
> implementation of self-insert-command directly rather than invoking
> the function in the symbol's function slot.
> 
> Isn't it a bug?

When C functions call other C functions they use the normal C linker, 
they don't go through the Lisp interpreter.

It would be possible for them to do this, but it would require extra 
coding and would probably have performance implications.

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***

^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: Overriding self-insert-command doesn't work
  2007-03-12 19:30     ` David Hansen
@ 2007-03-13  2:04       ` Drew Adams
  0 siblings, 0 replies; 7+ messages in thread
From: Drew Adams @ 2007-03-13  2:04 UTC (permalink / raw)
  To: help-gnu-emacs

> > if you know ways other than advising to change the definition
> > of self-insert-command transpararently then I'm all ears.
> 
> (define-key map [remap self-insert-command] #'my-version-of-self-insert)
> 
> or add some function to `after-change-functions'.  The first one
> requires emacs 22 (AFAIK).

I use this, which works for various Emacs versions:

(if (fboundp 'command-remapping)
    (define-key map (vector 'remap old) new)
  (substitute-key-definition old new map)))

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Overriding self-insert-command doesn't work
  2007-03-12 18:30   ` spamfilteraccount
  2007-03-12 19:30     ` David Hansen
  2007-03-13  1:25     ` Barry Margolin
@ 2007-03-14 14:17     ` Robert Thorpe
  2 siblings, 0 replies; 7+ messages in thread
From: Robert Thorpe @ 2007-03-14 14:17 UTC (permalink / raw)
  To: help-gnu-emacs

On Mar 12, 6:30 pm, "spamfilteracco...@gmail.com"
<spamfilteracco...@gmail.com> wrote:
> On Mar 12, 6:23 pm, "Robert Thorpe" <rtho...@realworldtech.com> wrote:
> > The command "self-insert-command" is inbuilt to Emacs.  It is part of
> > the static binary executable and is called directly by other parts of
> > that executable.  Changing it cannot change this version.
>
> That's not very nice, is it? Regardless of whether it's built-in,
> implemented in C, it should behave as a proper lisp symbol. I don't
> see why built-in functions should have to call the internal
> implementation of self-insert-command directly rather than invoking
> the function in the symbol's function slot.
>
> Isn't it a bug?

The intention is only to have one interface into changing how
keychords work, the keymap.  Read the section in the Emacs Lisp Manual
on keymaps, and the posts other people have put here.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2007-03-14 14:17 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-03-10 16:56 Overriding self-insert-command doesn't work spamfilteraccount
2007-03-12 17:23 ` Robert Thorpe
2007-03-12 18:30   ` spamfilteraccount
2007-03-12 19:30     ` David Hansen
2007-03-13  2:04       ` Drew Adams
2007-03-13  1:25     ` Barry Margolin
2007-03-14 14:17     ` Robert Thorpe

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.