all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Newbie: Unable to write a custom function
@ 2006-12-02 21:23 deech
  2006-12-02 21:52 ` Andre Kuehne
  2006-12-04  9:03 ` Mathias Dahl
  0 siblings, 2 replies; 5+ messages in thread
From: deech @ 2006-12-02 21:23 UTC (permalink / raw)


Hi all,
I am new to Emacs. I have written a new search function into my .emacs
file but I am unable to invoke it with M-x when I restart Emacs. There
are no error messages when Emacs starts up. Here is the code:

;;Search backwards from a point for a string. If found delete
;;all characters from that string to the point.
;;Eg Given the argument 't', 'alligator' becomes 'alliga'
(defun isearch-backward-tophrase ()
  (set-mark-command ())
  (isearch-backward )
  (kill-region ()())
)

Any idea what I am doing wrong?

Thanks...
Deech

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

* Re: Newbie: Unable to write a custom function
  2006-12-02 21:23 Newbie: Unable to write a custom function deech
@ 2006-12-02 21:52 ` Andre Kuehne
  2006-12-03  0:06   ` Dieter Wilhelm
  2006-12-04  9:03 ` Mathias Dahl
  1 sibling, 1 reply; 5+ messages in thread
From: Andre Kuehne @ 2006-12-02 21:52 UTC (permalink / raw)
  Cc: help-gnu-emacs

deech wrote:
> Hi all,
> I am new to Emacs. I have written a new search function into my .emacs
> file but I am unable to invoke it with M-x when I restart Emacs. There
> are no error messages when Emacs starts up. Here is the code:
> 
> ;;Search backwards from a point for a string. If found delete
> ;;all characters from that string to the point.
> ;;Eg Given the argument 't', 'alligator' becomes 'alliga'
> (defun isearch-backward-tophrase ()
>   (set-mark-command ())
>   (isearch-backward )
>   (kill-region ()())
> )
> 
> Any idea what I am doing wrong?

You have to use the (interactive) special form to make your
funtion invokable with M-x:

(defun isearch-backward-tophrase ()
    (interactive)
    ...

Regards
Andre

> Thanks...
> Deech
> 
> _______________________________________________
> help-gnu-emacs mailing list
> help-gnu-emacs@gnu.org
> http://lists.gnu.org/mailman/listinfo/help-gnu-emacs
> 

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

* Re: Newbie: Unable to write a custom function
  2006-12-02 21:52 ` Andre Kuehne
@ 2006-12-03  0:06   ` Dieter Wilhelm
  0 siblings, 0 replies; 5+ messages in thread
From: Dieter Wilhelm @ 2006-12-03  0:06 UTC (permalink / raw)
  Cc: deech, help-gnu-emacs

Andre Kuehne <andre.kuehne@gmx.net> writes:

> deech wrote:
>> Hi all,
>> I am new to Emacs. I have written a new search function into my .emacs
>> file but I am unable to invoke it with M-x when I restart Emacs. There
>> are no error messages when Emacs starts up. Here is the code:
>>
>> ;;Search backwards from a point for a string. If found delete
>> ;;all characters from that string to the point.
>> ;;Eg Given the argument 't', 'alligator' becomes 'alliga'
>> (defun isearch-backward-tophrase ()
>>   (set-mark-command ())
>>   (isearch-backward )
>>   (kill-region ()())
>> )
>>
>> Any idea what I am doing wrong?
>
> You have to use the (interactive) special form to make your
> funtion invokable with M-x:
>
> (defun isearch-backward-tophrase ()
>    (interactive)
>    ...

...

By the way, please try it without the mark, at least in interactive
mode isearch-backward sets the mark where it starts the search.


-- 
    Best wishes

    H. Dieter Wilhelm
    Darmstadt, Germany

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

* Re: Newbie: Unable to write a custom function
  2006-12-02 21:23 Newbie: Unable to write a custom function deech
  2006-12-02 21:52 ` Andre Kuehne
@ 2006-12-04  9:03 ` Mathias Dahl
  2006-12-06 17:49   ` Uber_Micro
  1 sibling, 1 reply; 5+ messages in thread
From: Mathias Dahl @ 2006-12-04  9:03 UTC (permalink / raw)


"deech" <aditya.siram@gmail.com> writes:

> ;;Search backwards from a point for a string. If found delete
> ;;all characters from that string to the point.
> ;;Eg Given the argument 't', 'alligator' becomes 'alliga'
> (defun isearch-backward-tophrase ()
>   (set-mark-command ())
>   (isearch-backward )
>   (kill-region ()())
> )

Maybe this is what you want:

(defun del-back-to-string (str)
  (interactive "sString: ")
  (let ((start (point)))
    (if (search-backward str nil t)
        (kill-region (point) start))))

Also, you don't have to restart Emacs to test your new command; just
place point after the last parenthesis and type C-x C-e
(`eval-last-sexp') and it will be evaluated and ready to be used.

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

* Re: Newbie: Unable to write a custom function
  2006-12-04  9:03 ` Mathias Dahl
@ 2006-12-06 17:49   ` Uber_Micro
  0 siblings, 0 replies; 5+ messages in thread
From: Uber_Micro @ 2006-12-06 17:49 UTC (permalink / raw)


Mathias Dahl <brakjoller@gmail.com> writes:


> Maybe this is what you want:
> 
> (defun del-back-to-string (str)
>   (interactive "sString: ")
>    ...


(interactive "*sString: ")

just a good habit to get into, "*" in front checks for read only
buffer 



-- 
So I remember, (ispell-buffer)

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

end of thread, other threads:[~2006-12-06 17:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-12-02 21:23 Newbie: Unable to write a custom function deech
2006-12-02 21:52 ` Andre Kuehne
2006-12-03  0:06   ` Dieter Wilhelm
2006-12-04  9:03 ` Mathias Dahl
2006-12-06 17:49   ` Uber_Micro

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.