From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: weemattisnot Newsgroups: gmane.emacs.help Subject: Re: Bug, or newbie error? Date: Wed, 6 Jul 2011 09:24:36 -0700 (PDT) Message-ID: <32006326.post@talk.nabble.com> References: <31975451.post@talk.nabble.com> <8762nl34eg.fsf@ericabrahamsen.net> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1309970309 13389 80.91.229.12 (6 Jul 2011 16:38:29 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 6 Jul 2011 16:38:29 +0000 (UTC) To: Help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Jul 06 18:38:25 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 1QeV7J-0005rS-3l for geh-help-gnu-emacs@m.gmane.org; Wed, 06 Jul 2011 18:38:25 +0200 Original-Received: from localhost ([::1]:55339 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QeV7H-0004zX-RZ for geh-help-gnu-emacs@m.gmane.org; Wed, 06 Jul 2011 12:38:24 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:49315) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QeUu0-000278-TS for Help-gnu-emacs@gnu.org; Wed, 06 Jul 2011 12:24:42 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QeUtx-0006Lx-NE for Help-gnu-emacs@gnu.org; Wed, 06 Jul 2011 12:24:40 -0400 Original-Received: from sam.nabble.com ([216.139.236.26]:48209) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QeUtx-0006Lc-FZ for Help-gnu-emacs@gnu.org; Wed, 06 Jul 2011 12:24:37 -0400 Original-Received: from isper.nabble.com ([192.168.236.156]) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1QeUtw-00057c-AW for Help-gnu-emacs@gnu.org; Wed, 06 Jul 2011 09:24:36 -0700 In-Reply-To: <8762nl34eg.fsf@ericabrahamsen.net> X-Nabble-From: mde@rhthm.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 216.139.236.26 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:81508 Archived-At: Awesome. This worked. Thank you! Eric Abrahamsen-2 wrote: > > 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 > > > > -- View this message in context: http://old.nabble.com/Bug%2C-or-newbie-error--tp31975451p32006326.html Sent from the Emacs - Help mailing list archive at Nabble.com.