all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Bug, or newbie error?
@ 2011-07-01 17:23 weemattisnot
  2011-07-02  0:36 ` Eric Abrahamsen
  0 siblings, 1 reply; 3+ messages in thread
From: weemattisnot @ 2011-07-01 17:23 UTC (permalink / raw
  To: Help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 938 bytes --]


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: http://old.nabble.com/Bug%2C-or-newbie-error--tp31975451p31975451.html
Sent from the Emacs - Help mailing list archive at Nabble.com.

[-- Attachment #2: Type: text/html, Size: 1079 bytes --]

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

* Re: Bug, or newbie error?
  2011-07-01 17:23 Bug, or newbie error? weemattisnot
@ 2011-07-02  0:36 ` Eric Abrahamsen
  2011-07-06 16:24   ` weemattisnot
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Abrahamsen @ 2011-07-02  0:36 UTC (permalink / raw
  To: help-gnu-emacs

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




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

* Re: Bug, or newbie error?
  2011-07-02  0:36 ` Eric Abrahamsen
@ 2011-07-06 16:24   ` weemattisnot
  0 siblings, 0 replies; 3+ messages in thread
From: weemattisnot @ 2011-07-06 16:24 UTC (permalink / raw
  To: Help-gnu-emacs


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.




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

end of thread, other threads:[~2011-07-06 16:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-01 17:23 Bug, or newbie error? weemattisnot
2011-07-02  0:36 ` Eric Abrahamsen
2011-07-06 16:24   ` weemattisnot

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.