From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Xah Lee Newsgroups: gmane.emacs.help Subject: Re: changing a variable with a keystroke Date: Wed, 14 Jan 2009 14:05:20 -0800 (PST) Organization: http://groups.google.com Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1231980535 5772 80.91.229.12 (15 Jan 2009 00:48:55 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 15 Jan 2009 00:48:55 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Jan 15 01:50:07 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1LNGQt-0000gi-Ns for geh-help-gnu-emacs@m.gmane.org; Thu, 15 Jan 2009 01:50:04 +0100 Original-Received: from localhost ([127.0.0.1]:58487 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LNGPd-0001D4-2I for geh-help-gnu-emacs@m.gmane.org; Wed, 14 Jan 2009 19:48:45 -0500 Original-Path: news.stanford.edu!newsfeed.stanford.edu!postnews.google.com!n33g2000pri.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 98 Original-NNTP-Posting-Host: 24.6.175.142 Original-X-Trace: posting.google.com 1231970720 11740 127.0.0.1 (14 Jan 2009 22:05:20 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Wed, 14 Jan 2009 22:05:20 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: n33g2000pri.googlegroups.com; posting-host=24.6.175.142; posting-account=bRPKjQoAAACxZsR8_VPXCX27T2YcsyMA User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_4_11; en) AppleWebKit/525.27.1 (KHTML, like Gecko) Version/3.2.1 Safari/525.27.1, gzip(gfe), gzip(gfe) Original-Xref: news.stanford.edu gnu.emacs.help:166011 X-Mailman-Approved-At: Wed, 14 Jan 2009 19:45:47 -0500 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:61339 Archived-At: On Jan 14, 3:32 am, Joff 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 variou= s > 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 press= ing > 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 =3D "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 g= ot > 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 =E2=88=91 http://xahlee.org/ =E2=98=84