all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* define-key and functions
@ 2003-12-06 17:49 Bill Rising
  2003-12-06 19:06 ` François Fleuret
  2003-12-06 19:15 ` Fredrik Arnerup
  0 siblings, 2 replies; 4+ messages in thread
From: Bill Rising @ 2003-12-06 17:49 UTC (permalink / raw)


Hello wizards,

Is there a way to use a function which takes arguments in define-key?

For instance:
(define-key global-map "C-m" 'foo-new-line)
runs the command foo-new-line if C-m is pressed.

Is there a way to pass an argument to foo-new-line?

I've read the define-key documentation, looked in a bunch of mode 
definitions and surfed the web looking at folks .emacs files, but I've 
not seen a way to pass an argument.

The real problem is that I would like to use a universal toggling 
program and simply pass the name of the variable to be toggled from some 
menu definitions. Perhaps I'm going about the problem in an entirely bad 
fashion.

Any help would be appreciated.

Bill

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

* Re: define-key and functions
  2003-12-06 17:49 define-key and functions Bill Rising
@ 2003-12-06 19:06 ` François Fleuret
  2003-12-06 19:15 ` Fredrik Arnerup
  1 sibling, 0 replies; 4+ messages in thread
From: François Fleuret @ 2003-12-06 19:06 UTC (permalink / raw)


Hi,

Bill Rising wrote on 06 Dec 2003 18:49:11 MET:

> Is there a way to use a function which takes arguments in define-key?

At least you can do something like

(defun an-example (universal) (interactive "P")
  (if universal (message "with ctrl-u") (message "without ctrl-u")))
(define-key global-map [(control x) (control x)] 'an-example)

With that C-x C-x writes "without ctrl-u" and C-u C-x C-x writes "with
ctrl-u". C-h f interactive for more fancy usages of the universal
argument.

Regards,

-- 
François Fleuret

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

* Re: define-key and functions
  2003-12-06 17:49 define-key and functions Bill Rising
  2003-12-06 19:06 ` François Fleuret
@ 2003-12-06 19:15 ` Fredrik Arnerup
  2003-12-06 19:19   ` Bill Rising
  1 sibling, 1 reply; 4+ messages in thread
From: Fredrik Arnerup @ 2003-12-06 19:15 UTC (permalink / raw)


Bill Rising <brising@louisville.edu> writes:

> Hello wizards,
>
> Is there a way to use a function which takes arguments in define-key?
>
> For instance:
> (define-key global-map "C-m" 'foo-new-line)
> runs the command foo-new-line if C-m is pressed.
>
> Is there a way to pass an argument to foo-new-line?

(define-key global-map "\C-m" 
  (lambda () (interactive) (foo-new-line argument)))

You really don't want to redefine C-m though. It's the same as Enter!

-- 
Fredrik Arnerup <e97_far@e.kth.se>

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

* Re: define-key and functions
  2003-12-06 19:15 ` Fredrik Arnerup
@ 2003-12-06 19:19   ` Bill Rising
  0 siblings, 0 replies; 4+ messages in thread
From: Bill Rising @ 2003-12-06 19:19 UTC (permalink / raw)


In article <87wu99oj0i.fsf@e.kth.se>,
 Fredrik Arnerup <e97_far@e.kth.se> wrote:

> Bill Rising <brising@louisville.edu> writes:
> 
> > Hello wizards,
> >
> > Is there a way to use a function which takes arguments in define-key?
> >
> > For instance:
> > (define-key global-map "C-m" 'foo-new-line)
> > runs the command foo-new-line if C-m is pressed.
> >
> > Is there a way to pass an argument to foo-new-line?
> 
> (define-key global-map "\C-m" 
>   (lambda () (interactive) (foo-new-line argument)))

Ahh... (slaps self on forehead)
Works like a dream.

> 
> You really don't want to redefine C-m though. It's the same as Enter!

I understand. It was the first keystroke that came to mind.

Thanks muchly.

Bill

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

end of thread, other threads:[~2003-12-06 19:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-12-06 17:49 define-key and functions Bill Rising
2003-12-06 19:06 ` François Fleuret
2003-12-06 19:15 ` Fredrik Arnerup
2003-12-06 19:19   ` Bill Rising

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.