help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [External] : Q3 - how to delete by words, not cut?


From: Tatsu Takamaro
Subject: Re: [External] : Q3 - how to delete by words, not cut?
Date: Thu, 19 Dec 2024 02:54:35 +0300
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.10.0

   *Did you try the `my-backward-delete-word' command I defined for you?*

Sorry, I didn't try it before. Because I didn't understand it by that time (and I have a habbit not to run any code until I understand it good enough). But now I dived into it and got it... Though the function logic is clear, the key binding won't work. I tried different keys. Here is the current state:

       *(defun tt-delword-backward (arg)**
       **"Delete backward arg words. (default 1)"**
       **(interactive "C-;")**
       **  (let**
       **  ((opt  (point)))**
       **  (backward-word arg)**
       **  (delete-region opt (point))**
       **  )**
       **)**
       **
       **(defun tt-delword-forward (arg)**
       **"Delete forward arg words. (default 1)"**
       **(interactive "C-'")**
       **  (let**
       **  ((opt  (point)))**
       **  (forward-word arg)**
       **  (delete-region opt (point))**
       **  )**
       **)*

I tried to set (interactive "b") and (interactive "f") for backward and forward respectively. When "C-;" is set the minibuffers says it's undefined, when letters are set it just type letters. The call by M-x doesn't do the job either.


вт, 17.12.2024 5:28, Drew Adams пишет:
I assume I would do it by a cycle - delete one char per
each iteration until the char is a space.
Do what?  Delete a word backwards?  Did you try the
`my-backward-delete-word' command I defined for you?

But I don't know Elisp...
Time to learn a little, if you want to define your
own commands.  I recommend you look into the Intro
Elisp manual: `C-h i m intro TAB RET'.

The command I defined saves the current cursor
location (point); then it uses predefined function
`backward-word', to move backward a word; then it
uses predefined function `delete-region', to delete
the text between the new location (point) and the
original (saved) location.

If you want to define deletion (not kill) commands,
then use `delete-region' (or other deletion functions).
They're building-block functions, not commands.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]