all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Xah Lee <xahlee@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: changing a variable with a keystroke
Date: Wed, 14 Jan 2009 14:05:20 -0800 (PST)	[thread overview]
Message-ID: <c3158ca2-a3a8-406d-a616-c5837fd81fbb@n33g2000pri.googlegroups.com> (raw)
In-Reply-To: mailman.4829.1231934186.26697.help-gnu-emacs@gnu.org



On Jan 14, 3:32 am, Joff <jack.j...@gmail.com> wrote:
> Dear all,
>
>  I'm having trouble trying to create a key combination to set a global
> variable. I have tried putting the following in my .emacs file:
>
> (global-set-key (kbd "C-l") nil)
> (global-set-key (kbd "C-l C-r") '(setq dired-listing-switches "-lR")
>
> and various permutions of the '(setq .. "-lR") part (with a single quote in
> front of the -lR, without the intial single quote etc. This got me various
> errors:
>
> (global-set-key (kbd "C-l C-r") (setq dired-listing-switches -lR))   -->
> Symbol's value as variable is void: -lR
>
> (global-set-key (kbd "C-l C-r") '(setq dired-listing-switches -lR))  -->
> Wrong type argument: commandp, (setq dired-listing-switches -lR) on pressing
> C-l C-r
>
> (global-set-key (kbd "C-l C-r") (setq dired-listing-switches "-lR"))  -->
> Printed -lR into my buffer when I pressed C-l C-r
>
> and so on...

Here's what's wrong with your code. Using pseudo C-like code to
illustrate, what you want is:

setkey(keyCode, functionName)

but what you are doing is:

setkey(keyCode, diredswich = "lr")

So, your second argument is supposed to be a function, but you give it
a expression of what the function is supposed to do.

To fix, you can define your function, then put the function name as
the second arg to setkey. But since elisp has a function construct
(aka lambda), so you don't need to define it separately.

Here's the code:

(global-set-key (kbd "C-l C-r")
 (lambda () (setq dired-listing-switches "-lR"))
) ;; code not tested

-----------------

Note that what you are doing is strange. Depending what you want to
achieve, there are probably better ways.


---------------------


> so then I tried
>
> (defun set_recursive_dired () "Set dired mode to recursive view"
>   (interactive "p")
>   (setq dired-listing-switches "-lR"))
>
> (global-set-key (kbd "C-l") nil)
> (global-set-key (kbd "C-l C-r") 'set_recursive_dired)
> because I thought setq might not be a command (?) which got me:

if you want to define it separately, you can do it like this:

(defun set_recursive_dired ()
  "Set dired mode to recursive view"
  (setq dired-listing-switches "-lR"))

> as you can probably tell, I'm pretty new to lisp/elisp... I have tried
> 'reading the error messages' and have done a lot of googling, which has got
> me this far (and which suggested the above '(defun...set_recursive_dired) )
>
> so could anyone kindly shed some light on why the above don't work, and
> perhaps suggest what I should be trying? Is it a syntax thing or am I
> missing the point completely?

lisp syntax gets a bit used to, but partly also because it is
irregular, and inconsistant in its eval/not-eval expectation in its
various functions ...

my website has a elisp tutorial you might be interested.

  Xah
∑ http://xahlee.org/

       reply	other threads:[~2009-01-14 22:05 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.4829.1231934186.26697.help-gnu-emacs@gnu.org>
2009-01-14 22:05 ` Xah Lee [this message]
2009-01-15  8:48   ` changing a variable with a keystroke Joff
2009-01-15 18:51     ` Tassilo Horn
     [not found]     ` <mailman.4960.1232045493.26697.help-gnu-emacs@gnu.org>
2009-01-16 11:19       ` Muurimäki Perttu
2009-01-14 11:32 Joff
2009-01-14 12:14 ` Juanma Barranquero

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=c3158ca2-a3a8-406d-a616-c5837fd81fbb@n33g2000pri.googlegroups.com \
    --to=xahlee@gmail.com \
    --cc=help-gnu-emacs@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.