From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eric Abrahamsen Newsgroups: gmane.emacs.help Subject: Re: Bug, or newbie error? Date: Fri, 01 Jul 2011 20:36:07 -0400 Message-ID: <8762nl34eg.fsf@ericabrahamsen.net> References: <31975451.post@talk.nabble.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1309567707 32160 80.91.229.12 (2 Jul 2011 00:48:27 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 2 Jul 2011 00:48:27 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Jul 02 02:48:22 2011 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1QcoNh-0002W6-66 for geh-help-gnu-emacs@m.gmane.org; Sat, 02 Jul 2011 02:48:21 +0200 Original-Received: from localhost ([::1]:41254 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QcoNg-0006Jk-82 for geh-help-gnu-emacs@m.gmane.org; Fri, 01 Jul 2011 20:48:20 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:56108) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QcoLl-0006JB-0D for help-gnu-emacs@gnu.org; Fri, 01 Jul 2011 20:46:22 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QcoLj-000646-2R for help-gnu-emacs@gnu.org; Fri, 01 Jul 2011 20:46:20 -0400 Original-Received: from lo.gmane.org ([80.91.229.12]:43151) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QcoC7-00057q-Kq for help-gnu-emacs@gnu.org; Fri, 01 Jul 2011 20:36:23 -0400 Original-Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1QcoC6-0007Si-2D for help-gnu-emacs@gnu.org; Sat, 02 Jul 2011 02:36:22 +0200 Original-Received: from 63-252-41-2.ip.mcleodusa.net ([63.252.41.2]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 02 Jul 2011 02:36:22 +0200 Original-Received: from eric by 63-252-41-2.ip.mcleodusa.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 02 Jul 2011 02:36:22 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 45 Original-X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: 63-252-41-2.ip.mcleodusa.net User-Agent: Gnus/5.110018 (No Gnus v0.18) Emacs/23.2 (gnu/linux) Cancel-Lock: sha1:2HAK/NP9M6u8WIanA9qwYEqEVTQ= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 80.91.229.12 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:81476 Archived-At: On Fri, Jul 01 2011, weemattisnot wrote: > I am trying to write a bit of lisp to go in my .emacs file that binds > C-1 to a command to change the color of the selected text (in > enriched text minor-mode). I have success running the command M-x > facemenu-set-foreground where I am prompted for a color, I type red, > and it changes the selected region red. But, when I try to bind this > command to a key-press, it doesn't work correctly, changing the color > of the text at the very end of the document (such that if I add any > text at the end of the document, it will be red). Here is my .emacs > lisp (defun headingone () (interactive) (facemenu-set-foreground > "red") ) (global-set-key (kbd "C-1") 'headingone) Have I done > something wrong here? Any suggestions are welcome. Thank you in > advance. Weemattisnot > > View this message in context: Bug, or newbie error? > Sent from the Emacs - Help mailing list archive at Nabble.com. If you look at the documentation for facemenu-set-foreground you'll see that it takes one mandatory argument (the color), and two optional arguments (point and mark). Since your command is calling this function, your command needs to first collect all the input that the function might need. That means your command needs to use the interactive code (see "Interactive Codes" in the e-lisp manual) that picks up the region. That happens to be "r". Since "r" passes your command two arguments, your command signature has to allow for those arguments. So: (defun headingone (start end) (interactive "r") (facemenu-set-foreground "red" start end)) That will turn stuff red whether you have an active region or not (probably not what you want), so you can check if there's an active region before doing anything: (defun headingone-2 (&optional start end) (interactive "r") (if (use-region-p) (facemenu-set-foreground "red" start end) (message "No active region"))) Hope that helps, Eric