all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* How run a command JUST on region highlighted by MOUSE?!?!
@ 2003-08-28 21:24 Christian Seberino
  2003-08-28 21:32 ` Andrew Taylor
  0 siblings, 1 reply; 11+ messages in thread
From: Christian Seberino @ 2003-08-28 21:24 UTC (permalink / raw)


I have a need to run delete-trailing-whitespace on JUST the region
highlighted with mouse.  Can I do this??

Chris

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

* Re: How run a command JUST on region highlighted by MOUSE?!?!
  2003-08-28 21:24 How run a command JUST on region highlighted by MOUSE?!?! Christian Seberino
@ 2003-08-28 21:32 ` Andrew Taylor
  2003-08-29 18:22   ` Christian Seberino
  0 siblings, 1 reply; 11+ messages in thread
From: Andrew Taylor @ 2003-08-28 21:32 UTC (permalink / raw)


Christian Seberino wrote:
> I have a need to run delete-trailing-whitespace on JUST the region
> highlighted with mouse.  Can I do this??

Select the region, M-x narrow-to-region, M-x delete-trailing-whitespace, 
  M-x widen.

-- 
Andrew

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

* Re: How run a command JUST on region highlighted by MOUSE?!?!
  2003-08-28 21:32 ` Andrew Taylor
@ 2003-08-29 18:22   ` Christian Seberino
  2003-08-29 18:34     ` Oliver Scholz
                       ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Christian Seberino @ 2003-08-29 18:22 UTC (permalink / raw)


Andrew

Thanks for the help.  Can I please ask you a related question on usage
of narrow-to-region?

I set .emacs up to run this function when I highlight a region with
mouse
and type C-ac.....

 (defun cs-py-comment-region() (interactive)
      (narrow-to-region)
      (py-comment-region)
      (delete-trailing-whitespace)
      (widen))

I'm getting this error message...

cs-py-comment-region: Wrong number of arguments: #<subr
narrow-to-region>, 0
(New file)
Mark set
cs-py-comment-region: Wrong number of arguments: #<subr
narrow-to-region>, 0

I read Emacs LISP reference manual on narrow-to-region and it said..

Command: narrow-to-region start end
    This function sets the accessible portion of the current buffer to
start at start and end at end. Both arguments should be character
positions.

    In an interactive call, start and end are set to the bounds of the
current region (point and the mark, with the smallest first).


I assume "interactive call" = "highlighted a region with mouse"??

It seems narrow-to-region should get the start and end point values
automatically??!

Can I still make this work?

Any help would be greatly appreciated.

Sincerely,

Chris

Andrew Taylor <ataylor@its.to> wrote in message news:<5yu3b.865304$3C2.19502799@news3.calgary.shaw.ca>...
> Christian Seberino wrote:
> > I have a need to run delete-trailing-whitespace on JUST the region
> > highlighted with mouse.  Can I do this??
> 
> Select the region, M-x narrow-to-region, M-x delete-trailing-whitespace, 
>   M-x widen.

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

* Re: How run a command JUST on region highlighted by MOUSE?!?!
  2003-08-29 18:22   ` Christian Seberino
@ 2003-08-29 18:34     ` Oliver Scholz
  2003-09-03  0:03       ` Christian Seberino
  2003-09-03  0:19       ` Christian Seberino
  2003-08-29 18:56     ` Johan Bockgård
  2003-08-29 21:45     ` Kevin Rodgers
  2 siblings, 2 replies; 11+ messages in thread
From: Oliver Scholz @ 2003-08-29 18:34 UTC (permalink / raw)


seberino@spawar.navy.mil (Christian Seberino) writes:

> Andrew
>
> Thanks for the help.  Can I please ask you a related question on usage
> of narrow-to-region?
>
> I set .emacs up to run this function when I highlight a region with
> mouse
> and type C-ac.....
>
>  (defun cs-py-comment-region() (interactive)
>       (narrow-to-region)
                        ^^^
>       (py-comment-region)
>       (delete-trailing-whitespace)
>       (widen))
         ^^^^

[untested]

(defun cs-py-comment-region (beg end)
  (interactive "r")
  (save-restriction
    (narrow-to-region beg end)
    (py-comment-region)
    (delete-trailing-whitespace)))

    Oliver
-- 
12 Fructidor an 211 de la Révolution
Liberté, Egalité, Fraternité!

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

* Re: How run a command JUST on region highlighted by MOUSE?!?!
  2003-08-29 18:22   ` Christian Seberino
  2003-08-29 18:34     ` Oliver Scholz
@ 2003-08-29 18:56     ` Johan Bockgård
  2003-08-29 21:45     ` Kevin Rodgers
  2 siblings, 0 replies; 11+ messages in thread
From: Johan Bockgård @ 2003-08-29 18:56 UTC (permalink / raw)


seberino@spawar.navy.mil (Christian Seberino) writes:

> Command: narrow-to-region start end
[...]
> In an interactive call, start and end are set to the bounds of the
> current region (point and the mark, with the smallest first).
>
>
> I assume "interactive call" = "highlighted a region with mouse"??

Interactive call means calling the command with M-x narrow-to-region

-- 
Johan Bockgård

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

* Re: How run a command JUST on region highlighted by MOUSE?!?!
  2003-08-29 18:22   ` Christian Seberino
  2003-08-29 18:34     ` Oliver Scholz
  2003-08-29 18:56     ` Johan Bockgård
@ 2003-08-29 21:45     ` Kevin Rodgers
  2003-09-03  0:16       ` Christian Seberino
  2 siblings, 1 reply; 11+ messages in thread
From: Kevin Rodgers @ 2003-08-29 21:45 UTC (permalink / raw)


Christian Seberino wrote:

> I set .emacs up to run this function when I highlight a region with
> mouse
> and type C-ac.....
> 
>  (defun cs-py-comment-region() (interactive)
>       (narrow-to-region)
>       (py-comment-region)
>       (delete-trailing-whitespace)
>       (widen))
> 
> I'm getting this error message...
> 
> cs-py-comment-region: Wrong number of arguments: #<subr narrow-to-region>, 0
> (New file)
> Mark set
> cs-py-comment-region: Wrong number of arguments: #<subr narrow-to-region>, 0
> 
> I read Emacs LISP reference manual on narrow-to-region and it said..
> 
> Command: narrow-to-region start end
>     This function sets the accessible portion of the current buffer to
> start at start and end at end. Both arguments should be character
> positions.
> 
>     In an interactive call, start and end are set to the bounds of the
> current region (point and the mark, with the smallest first).
> 
> 
> I assume "interactive call" = "highlighted a region with mouse"??
> 
> It seems narrow-to-region should get the start and end point values
> automatically??!

It does when you call it interactively.  When you call it programmatically,
you need to specify the START and END arguments: (region-beginning) and
(region-end), respectively.

Your cs-py-comment-region function should take 2 arguments, provide a
way for them to be specified when it's called interactively, and pass
the region bounds to py-comment-region:

(defun cs-py-comment-region (beg end)
   (interactive "r")
   (py-comment-region beg end)
   ...)

-- 
Kevin Rodgers

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

* Re: How run a command JUST on region highlighted by MOUSE?!?!
  2003-08-29 18:34     ` Oliver Scholz
@ 2003-09-03  0:03       ` Christian Seberino
  2003-09-03  0:19       ` Christian Seberino
  1 sibling, 0 replies; 11+ messages in thread
From: Christian Seberino @ 2003-09-03  0:03 UTC (permalink / raw)


Oliver

Thanks for the help.  I like your version and would very much like to
use it.
The "save-restriction" is a nice touch too.

I copied your version essentially verbatim into my .emacs....

   (defun cs-py-comment-region(beg end) (interactive "r")
    (save-restriction
      (narrow-to-region beg end)
      (py-comment-region)
      (delete-trailing-whitespace)))

It give me the following error message when I hightlight a region with
mouse
and then type C-ac which is setup to call this function....

save-restriction: Wrong number of arguments: (lambda (beg end
&optional arg) "Like `comment-region' but uses double hash (`#')
comment starter." (interactive "r
P") (let ((comment-start py-block-comment-prefix)) (comment-region beg
end arg))), 0

Do you know what this error means and how to fix?

Thanks again,

Chris

Oliver Scholz <alkibiades@gmx.de> wrote in message news:<uad9s9utz.fsf@ID-87814.user.dfncis.de>...
> seberino@spawar.navy.mil (Christian Seberino) writes:
> 
> > Andrew
> >
> > Thanks for the help.  Can I please ask you a related question on usage
> > of narrow-to-region?
> >
> > I set .emacs up to run this function when I highlight a region with
> > mouse
> > and type C-ac.....
> >
> >  (defun cs-py-comment-region() (interactive)
> >       (narrow-to-region)
>                      ^^^
> >       (py-comment-region)
> >       (delete-trailing-whitespace)
> >       (widen))
>          ^^^^
> 
> [untested]
> 
> (defun cs-py-comment-region (beg end)
>   (interactive "r")
>   (save-restriction
>     (narrow-to-region beg end)
>     (py-comment-region)
>     (delete-trailing-whitespace)))
> 
>     Oliver

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

* Re: How run a command JUST on region highlighted by MOUSE?!?!
  2003-08-29 21:45     ` Kevin Rodgers
@ 2003-09-03  0:16       ` Christian Seberino
  2003-09-03 22:04         ` Jeffery B. Rancier
  2003-09-03 23:13         ` Kevin Rodgers
  0 siblings, 2 replies; 11+ messages in thread
From: Christian Seberino @ 2003-09-03  0:16 UTC (permalink / raw)


Kevin

Thanks for your help.  I finally got a version that works!

  (defun cs-py-comment-region(beg end) (interactive "r")
    (save-restriction
      (narrow-to-region beg end)
      (py-comment-region beg end)
      (delete-trailing-whitespace)))
 

What does the (interactive "r") do??? I really ONLY ever invoke my
functions
with key-combos that are hard wired to start the functions....e.g.
C-ac, C-z, etc....
Does this mean I can omit all this (interactive ..) stuff from .emacs
everywhere???

It appears that beg and end got automagically set when I dragged mouse
over some region.

It also appears that although py-comment-region did not need it's 2
args
without narrow-to-region part... it does now when I add the
narrow-to-region
part and that was the main bug.

Thank goodness it works but there is a lot going on I don't understand
here
about how arguments get defined and (interactive..) function.  Any
help would
be greatly appreciated.

Sincerely,

Chris

Kevin Rodgers <ihs_4664@yahoo.com> wrote in message news:<3F4FC986.4060602@yahoo.com>...
> Christian Seberino wrote:
> 
> > I set .emacs up to run this function when I highlight a region with
> > mouse
> > and type C-ac.....
> > 
> >  (defun cs-py-comment-region() (interactive)
> >       (narrow-to-region)
> >       (py-comment-region)
> >       (delete-trailing-whitespace)
> >       (widen))
> > 
> > I'm getting this error message...
> > 
> > cs-py-comment-region: Wrong number of arguments: #<subr narrow-to-region>, 0
> > (New file)
> > Mark set
> > cs-py-comment-region: Wrong number of arguments: #<subr narrow-to-region>, 0
> > 
> > I read Emacs LISP reference manual on narrow-to-region and it said..
> > 
> > Command: narrow-to-region start end
> >     This function sets the accessible portion of the current buffer to
> > start at start and end at end. Both arguments should be character
> > positions.
> > 
> >     In an interactive call, start and end are set to the bounds of the
> > current region (point and the mark, with the smallest first).
> > 
> > 
> > I assume "interactive call" = "highlighted a region with mouse"??
> > 
> > It seems narrow-to-region should get the start and end point values
> > automatically??!
> 
> It does when you call it interactively.  When you call it programmatically,
> you need to specify the START and END arguments: (region-beginning) and
> (region-end), respectively.
> 
> Your cs-py-comment-region function should take 2 arguments, provide a
> way for them to be specified when it's called interactively, and pass
> the region bounds to py-comment-region:
> 
> (defun cs-py-comment-region (beg end)
>    (interactive "r")
>    (py-comment-region beg end)
>    ...)

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

* Re: How run a command JUST on region highlighted by MOUSE?!?!
  2003-08-29 18:34     ` Oliver Scholz
  2003-09-03  0:03       ` Christian Seberino
@ 2003-09-03  0:19       ` Christian Seberino
  1 sibling, 0 replies; 11+ messages in thread
From: Christian Seberino @ 2003-09-03  0:19 UTC (permalink / raw)


Oliver 

OK, I got your version to work after replacing (py-comment-region)
with  (py-comment-region beg end).  Can you please
explain the (interactive "r") and why you needed to add 2 args to
function at top?..--> (defun cs-py-comment-region(beg end) ..)

It all works but it would be nice to understand it too! 


Thanks again,

Chris

Oliver Scholz <alkibiades@gmx.de> wrote in message news:<uad9s9utz.fsf@ID-87814.user.dfncis.de>...
> seberino@spawar.navy.mil (Christian Seberino) writes:
> 
> > Andrew
> >
> > Thanks for the help.  Can I please ask you a related question on usage
> > of narrow-to-region?
> >
> > I set .emacs up to run this function when I highlight a region with
> > mouse
> > and type C-ac.....
> >
> >  (defun cs-py-comment-region() (interactive)
> >       (narrow-to-region)
>                      ^^^
> >       (py-comment-region)
> >       (delete-trailing-whitespace)
> >       (widen))
>          ^^^^
> 
> [untested]
> 
> (defun cs-py-comment-region (beg end)
>   (interactive "r")
>   (save-restriction
>     (narrow-to-region beg end)
>     (py-comment-region)
>     (delete-trailing-whitespace)))
> 
>     Oliver

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

* Re: How run a command JUST on region highlighted by MOUSE?!?!
  2003-09-03  0:16       ` Christian Seberino
@ 2003-09-03 22:04         ` Jeffery B. Rancier
  2003-09-03 23:13         ` Kevin Rodgers
  1 sibling, 0 replies; 11+ messages in thread
From: Jeffery B. Rancier @ 2003-09-03 22:04 UTC (permalink / raw)


seberino@spawar.navy.mil (Christian Seberino) writes:

,----[ C-h f interactive RET ]
| interactive is a special form.
| (interactive ARGS)
| 
| Specify a way of parsing arguments for interactive use of a function.
| For example, write
|   (defun foo (arg) "Doc string" (interactive "p") ...use arg...)
| to make ARG be the prefix argument when `foo' is called as a command.
| The "call" to `interactive' is actually a declaration rather than a function;
|  it tells `call-interactively' how to read arguments
|  to pass to the function.
| When actually called, `interactive' just returns nil.
| 
| The argument of `interactive' is usually a string containing a code letter
|  followed by a prompt.  (Some code letters do not use I/O to get
|  the argument and do not need prompts.)  To prompt for multiple arguments,
|  give a code letter, its prompt, a newline, and another code letter, etc.
|  Prompts are passed to format, and may use % escapes to print the
|  arguments that have already been read.
| If the argument is not a string, it is evaluated to get a list of
|  arguments to pass to the function.
| Just `(interactive)' means pass no args when calling interactively.
| 
| Code letters available are:
| a -- Function name: symbol with a function definition.
| b -- Name of existing buffer.
| B -- Name of buffer, possibly nonexistent.
| c -- Character (no input method is used).
| C -- Command name: symbol with interactive function definition.
| d -- Value of point as number.  Does not do I/O.
| D -- Directory name.
| e -- Parametrized event (i.e., one that's a list) that invoked this command.
|      If used more than once, the Nth `e' returns the Nth parameterized event.
|      This skips events that are integers or symbols.
| f -- Existing file name.
| F -- Possibly nonexistent file name.
| i -- Ignored, i.e. always nil.  Does not do I/O.
| k -- Key sequence (downcase the last event if needed to get a definition).
| K -- Key sequence to be redefined (do not downcase the last event).
| m -- Value of mark as number.  Does not do I/O.
| M -- Any string.  Inherits the current input method.
| n -- Number read using minibuffer.
| N -- Raw prefix arg, or if none, do like code `n'.
| p -- Prefix arg converted to number.  Does not do I/O.
| P -- Prefix arg in raw form.  Does not do I/O.
| r -- Region: point and mark as 2 numeric args, smallest first.  Does no I/O.
| s -- Any string.  Does not inherit the current input method.
| S -- Any symbol.
| v -- Variable name: symbol that is user-variable-p.
| x -- Lisp expression read but not evaluated.
| X -- Lisp expression read and evaluated.
| z -- Coding system.
| Z -- Coding system, nil if no prefix arg.
| In addition, if the string begins with `*'
|  then an error is signaled if the buffer is read-only.
|  This happens before reading any arguments.
| If the string begins with `@', then Emacs searches the key sequence
|  which invoked the command for its first mouse click (or any other
|  event which specifies a window), and selects that window before
|  reading any arguments.  You may use both `@' and `*'; they are
|  processed in the order that they appear.
`----


> Kevin
>
> Thanks for your help.  I finally got a version that works!
>
>   (defun cs-py-comment-region(beg end) (interactive "r")
>     (save-restriction
>       (narrow-to-region beg end)
>       (py-comment-region beg end)
>       (delete-trailing-whitespace)))
>  
>
> What does the (interactive "r") do??? I really ONLY ever invoke my
> functions
> with key-combos that are hard wired to start the functions....e.g.
> C-ac, C-z, etc....
> Does this mean I can omit all this (interactive ..) stuff from .emacs
> everywhere???
>
> It appears that beg and end got automagically set when I dragged mouse
> over some region.
>
> It also appears that although py-comment-region did not need it's 2
> args
> without narrow-to-region part... it does now when I add the
> narrow-to-region
> part and that was the main bug.
>
> Thank goodness it works but there is a lot going on I don't understand
> here
> about how arguments get defined and (interactive..) function.  Any
> help would
> be greatly appreciated.
>
> Sincerely,
>
> Chris
>
> Kevin Rodgers <ihs_4664@yahoo.com> wrote in message news:<3F4FC986.4060602@yahoo.com>...
>> Christian Seberino wrote:
>> 
>> > I set .emacs up to run this function when I highlight a region with
>> > mouse
>> > and type C-ac.....
>> > 
>> >  (defun cs-py-comment-region() (interactive)
>> >       (narrow-to-region)
>> >       (py-comment-region)
>> >       (delete-trailing-whitespace)
>> >       (widen))
>> > 
>> > I'm getting this error message...
>> > 
>> > cs-py-comment-region: Wrong number of arguments: #<subr narrow-to-region>, 0
>> > (New file)
>> > Mark set
>> > cs-py-comment-region: Wrong number of arguments: #<subr narrow-to-region>, 0
>> > 
>> > I read Emacs LISP reference manual on narrow-to-region and it said..
>> > 
>> > Command: narrow-to-region start end
>> >     This function sets the accessible portion of the current buffer to
>> > start at start and end at end. Both arguments should be character
>> > positions.
>> > 
>> >     In an interactive call, start and end are set to the bounds of the
>> > current region (point and the mark, with the smallest first).
>> > 
>> > 
>> > I assume "interactive call" = "highlighted a region with mouse"??
>> > 
>> > It seems narrow-to-region should get the start and end point values
>> > automatically??!
>> 
>> It does when you call it interactively.  When you call it programmatically,
>> you need to specify the START and END arguments: (region-beginning) and
>> (region-end), respectively.
>> 
>> Your cs-py-comment-region function should take 2 arguments, provide a
>> way for them to be specified when it's called interactively, and pass
>> the region bounds to py-comment-region:
>> 
>> (defun cs-py-comment-region (beg end)
>>    (interactive "r")
>>    (py-comment-region beg end)
>>    ...)

-- 
Thanks,
Jeff

,----
| Jeffery B. Rancier
| 
| Softechnics
| a METTLER TOLEDO company
`----

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

* Re: How run a command JUST on region highlighted by MOUSE?!?!
  2003-09-03  0:16       ` Christian Seberino
  2003-09-03 22:04         ` Jeffery B. Rancier
@ 2003-09-03 23:13         ` Kevin Rodgers
  1 sibling, 0 replies; 11+ messages in thread
From: Kevin Rodgers @ 2003-09-03 23:13 UTC (permalink / raw)


Christian Seberino wrote:


> What does the (interactive "r") do??? I really ONLY ever invoke my
> functions
> with key-combos that are hard wired to start the functions....e.g.
> C-ac, C-z, etc....
> Does this mean I can omit all this (interactive ..) stuff from .emacs
> everywhere???


No, the interactive form allows the function to be bound to a key and
specifies what values its arguments (if any) get when it is invoked
interactively (i.e. via a key binding or `M-x').


> It appears that beg and end got automagically set when I dragged mouse
> over some region.


Exactly!


> It also appears that although py-comment-region did not need it's 2
> args
> without narrow-to-region part... it does now when I add the
> narrow-to-region
> part and that was the main bug.


That doesn't make sense to me.


> Thank goodness it works but there is a lot going on I don't understand
> here
> about how arguments get defined and (interactive..) function.  Any
> help would
> be greatly appreciated.


Everything you need to know is availabel via its doc string (`C-h v interactive')

and in the Emacs Lisp manual.

-- 
Kevin Rodgers

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

end of thread, other threads:[~2003-09-03 23:13 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-08-28 21:24 How run a command JUST on region highlighted by MOUSE?!?! Christian Seberino
2003-08-28 21:32 ` Andrew Taylor
2003-08-29 18:22   ` Christian Seberino
2003-08-29 18:34     ` Oliver Scholz
2003-09-03  0:03       ` Christian Seberino
2003-09-03  0:19       ` Christian Seberino
2003-08-29 18:56     ` Johan Bockgård
2003-08-29 21:45     ` Kevin Rodgers
2003-09-03  0:16       ` Christian Seberino
2003-09-03 22:04         ` Jeffery B. Rancier
2003-09-03 23:13         ` Kevin Rodgers

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.