From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: jeff.rancier@softechnics.com (Jeffery B. Rancier) Newsgroups: gmane.emacs.help Subject: Re: How run a command JUST on region highlighted by MOUSE?!?! Date: Wed, 03 Sep 2003 18:04:25 -0400 Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: References: <5yu3b.865304$3C2.19502799@news3.calgary.shaw.ca> <3F4FC986.4060602@yahoo.com> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1062683704 20696 80.91.224.253 (4 Sep 2003 13:55:04 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 4 Sep 2003 13:55:04 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Sep 04 15:55:02 2003 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 19uuZh-00079J-00 for ; Thu, 04 Sep 2003 15:55:02 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.22) id 19uuXW-0005ef-Nq for geh-help-gnu-emacs@m.gmane.org; Thu, 04 Sep 2003 09:52:46 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.22) id 19ufqX-0000w3-7V for help-gnu-emacs@gnu.org; Wed, 03 Sep 2003 18:11:25 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.22) id 19ufq5-0000gp-KP for help-gnu-emacs@gnu.org; Wed, 03 Sep 2003 18:10:59 -0400 Original-Received: from [80.91.224.249] (helo=main.gmane.org) by monty-python.gnu.org with esmtp (Exim 4.22) id 19ufos-0008UM-QU for help-gnu-emacs@gnu.org; Wed, 03 Sep 2003 18:09:42 -0400 Original-Received: from root by main.gmane.org with local (Exim 3.35 #1 (Debian)) id 19ufpN-0000ts-00 for ; Thu, 04 Sep 2003 00:10:13 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-To: help-gnu-emacs@gnu.org Original-Received: from sea.gmane.org ([80.91.224.252]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 19ufkI-0000qr-00 for ; Thu, 04 Sep 2003 00:04:58 +0200 Original-Received: from news by sea.gmane.org with local (Exim 3.35 #1 (Debian)) id 19ufjl-0000Jg-00 for ; Thu, 04 Sep 2003 00:04:25 +0200 Original-Lines: 162 Original-X-Complaints-To: usenet@sea.gmane.org User-Agent: Gnus/5.1002 (Gnus v5.10.2) Emacs/21.3 (windows-nt) Cancel-Lock: sha1:j8atcmPQlY0HpP/SRhrkP6e9wHY= X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.2 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 Xref: main.gmane.org gmane.emacs.help:12274 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:12274 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 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: #, 0 >> > (New file) >> > Mark set >> > cs-py-comment-region: Wrong number of arguments: #, 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 `----