* Deleting a word using keybinding @ 2020-10-15 10:26 Christopher Dimech 2020-10-15 11:10 ` Jeremie Juste ` (3 more replies) 0 siblings, 4 replies; 15+ messages in thread From: Christopher Dimech @ 2020-10-15 10:26 UTC (permalink / raw) To: Help Gnu Emacs I am trying to delete a word using keybinding string "C-<tab>" but the Chord is still showing as undefined. I would like to delete a word even if I happen to be in the middle of it., so I move backward. Here is the function ( global-set-key (kbd "C-<tab>" ) ( lambda () (interactive) ( (backward-word) (kill-word 1) ) ) ) ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Deleting a word using keybinding 2020-10-15 10:26 Deleting a word using keybinding Christopher Dimech @ 2020-10-15 11:10 ` Jeremie Juste 2020-10-15 11:20 ` Harald Jörg ` (2 subsequent siblings) 3 siblings, 0 replies; 15+ messages in thread From: Jeremie Juste @ 2020-10-15 11:10 UTC (permalink / raw) To: Christopher Dimech; +Cc: Help Gnu Emacs Hello, To investigate I usually separate the problem into two parts Frist the key binding and second the function. The function test work as you expect when calling M-x test (defun test () (interactive) (progn (backward-word) (kill-word 1)) ) (global-set-key (kbd "C-<tab>") 'test) For the keybinding I guess it will depend on the mode you are in. As tab is intensively used so a minor mode might take control of it if I understand correctly. A way to test it would be to test the binding in fundamental-mode. HTH, Jeremie ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Deleting a word using keybinding 2020-10-15 10:26 Deleting a word using keybinding Christopher Dimech 2020-10-15 11:10 ` Jeremie Juste @ 2020-10-15 11:20 ` Harald Jörg 2020-10-15 16:44 ` Christopher Dimech 2020-10-15 18:44 ` Christopher Dimech 2020-10-15 11:34 ` Stephen Berman 2020-10-15 13:48 ` Stefan Monnier 3 siblings, 2 replies; 15+ messages in thread From: Harald Jörg @ 2020-10-15 11:20 UTC (permalink / raw) To: Christopher Dimech, Help Gnu Emacs On 10/15/20 12:26 PM, Christopher Dimech wrote: > > I am trying to delete a word using keybinding string "C-<tab>" but the > Chord is still showing as undefined. > > I would like to delete a word even if I happen to be in the middle of > it., so I move backward. > > Here is the function > > ( global-set-key (kbd "C-<tab>" ) > ( lambda () (interactive) > ( (backward-word) > (kill-word 1) > ) > ) > ) If I get rid of one pair of parens, it works for me. ( global-set-key (kbd "C-<tab>" ) ( lambda () (interactive) (backward-word) (kill-word 1) ) ) With the extra parens in your code, I get 'Invalid function: (backward-word)'. Maybe this is why you don't see any effect? Also note that if your point happens to be on the first character of a word, this function deletes the _previous_ word. -- Cheers, haj ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Deleting a word using keybinding 2020-10-15 11:20 ` Harald Jörg @ 2020-10-15 16:44 ` Christopher Dimech 2020-10-15 18:44 ` Christopher Dimech 1 sibling, 0 replies; 15+ messages in thread From: Christopher Dimech @ 2020-10-15 16:44 UTC (permalink / raw) To: Harald Jörg; +Cc: Help Gnu Emacs Dear Haj, correct, if I happen toi be at the beginning of a word, it deletes the previous word. I would like to have it kill forward, so I modified as follows ( global-set-key (kbd "H-<delete>" ) ( lambda () (interactive) (forward-word) (kill-word 1) (message "**** Killing a word") ) ) A small remaining part to to kill the whole word even if I am in the middle of a word, because my code only deletes from the current point onwards. Sent: Thursday, October 15, 2020 at 1:20 PM From: "Harald Jörg" <haj@posteo.de> To: "Christopher Dimech" <dimech@gmx.com>, "Help Gnu Emacs" <help-gnu-emacs@gnu.org> Subject: Re: Deleting a word using keybinding On 10/15/20 12:26 PM, Christopher Dimech wrote: > > I am trying to delete a word using keybinding string "C-<tab>" but the > Chord is still showing as undefined. > > I would like to delete a word even if I happen to be in the middle of > it., so I move backward. > > Here is the function > > ( global-set-key (kbd "C-<tab>" ) > ( lambda () (interactive) > ( (backward-word) > (kill-word 1) > ) > ) > ) If I get rid of one pair of parens, it works for me. ( global-set-key (kbd "C-<tab>" ) ( lambda () (interactive) (backward-word) (kill-word 1) ) ) With the extra parens in your code, I get 'Invalid function: (backward-word)'. Maybe this is why you don't see any effect? Also note that if your point happens to be on the first character of a word, this function deletes the _previous_ word. -- Cheers, haj ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Deleting a word using keybinding 2020-10-15 11:20 ` Harald Jörg 2020-10-15 16:44 ` Christopher Dimech @ 2020-10-15 18:44 ` Christopher Dimech 2020-10-15 20:25 ` Harald Jörg 1 sibling, 1 reply; 15+ messages in thread From: Christopher Dimech @ 2020-10-15 18:44 UTC (permalink / raw) To: Harald Jörg; +Cc: Help Gnu Emacs I have updated my function to kill words forward so that even if I am in the middle of a word that word will be killed. I also consider that if there are multiple spaces, I delete just the spaces spaces but not next word. I am finding a problem however when deleting part of a sentence by contiuing to press C--<delete> because when the point happens to be between two words, I end up with the two words stuck together (the previous and thn forward), which deletes the two words when I hit C-<delete> again. (defun kill-spacword () (interactive) (if (looking-at "[ \t\n]") (let ((p (point))) ( re-search-forward "[^ \t\n]" nil :no-error ) ( backward-char ) ( kill-region p (point) ) ) ( progn (backward-char) (if (looking-at "[ \t\n]") (kill-word 1) ( progn (backward-word) (kill-word 1) ) ) ) ) ) Sent: Thursday, October 15, 2020 at 1:20 PM From: "Harald Jörg" <haj@posteo.de> To: "Christopher Dimech" <dimech@gmx.com>, "Help Gnu Emacs" <help-gnu-emacs@gnu.org> Subject: Re: Deleting a word using keybinding On 10/15/20 12:26 PM, Christopher Dimech wrote: > > I am trying to delete a word using keybinding string "C-<tab>" but the > Chord is still showing as undefined. > > I would like to delete a word even if I happen to be in the middle of > it., so I move backward. > > Here is the function > > ( global-set-key (kbd "C-<tab>" ) > ( lambda () (interactive) > ( (backward-word) > (kill-word 1) > ) > ) > ) If I get rid of one pair of parens, it works for me. ( global-set-key (kbd "C-<tab>" ) ( lambda () (interactive) (backward-word) (kill-word 1) ) ) With the extra parens in your code, I get 'Invalid function: (backward-word)'. Maybe this is why you don't see any effect? Also note that if your point happens to be on the first character of a word, this function deletes the _previous_ word. -- Cheers, haj ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Deleting a word using keybinding 2020-10-15 18:44 ` Christopher Dimech @ 2020-10-15 20:25 ` Harald Jörg 2020-10-15 20:59 ` Christopher Dimech 0 siblings, 1 reply; 15+ messages in thread From: Harald Jörg @ 2020-10-15 20:25 UTC (permalink / raw) To: Christopher Dimech; +Cc: Help Gnu Emacs On 10/15/20 8:44 PM, Christopher Dimech wrote: > I have updated my function to kill words forward so that even if I am > in the middle of a word that word will be killed. I also consider that > if there are multiple spaces, I delete just the spaces spaces but not > next word. This isn't exactly what the function does: If there are two or more spaces between words, then only spaces to the right of point are deleted. Also, when you delete _all_ spaces, you merge two words into one. This is the cause for your observation: > I am finding a problem however when deleting part of a sentence by > contiuing to press C--<delete> because when the point happens to be > between two words, I end up with the two words stuck together (the > previous and thn forward), which deletes the two words when I hit > C-<delete> again. It really pays off when you spend the effort to write down how you want the function to behave in all relevant situations. It is good practice to have a docstring for your command anyway, and you might detect contradictory requirements before you start writing the function. If point is before a whitespace character, you could either do nothing, or delete the previous, or delete the following word, all of them make some sense. Deleting whitespace seems somewhat unrelated. There still are cases where your function does not what you seem to expect: If the text in the buffer is "foo bar", and point is before the "a" in "bar", then executing M-x kill-spacword kills "foo". -- Cheers, haj ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Deleting a word using keybinding 2020-10-15 20:25 ` Harald Jörg @ 2020-10-15 20:59 ` Christopher Dimech 2020-10-15 21:06 ` Thien-Thi Nguyen 0 siblings, 1 reply; 15+ messages in thread From: Christopher Dimech @ 2020-10-15 20:59 UTC (permalink / raw) To: Harald Jörg; +Cc: Help Gnu Emacs I want it to behave as C-<delete>, except that I want to delete the current word if the cursor happens to be within a word. For instance, consider the following sentence. I want that if the cursor point in on the character w of the word Brown, the word Brown is also deleted, rather than deleting the word fromw onwards. The Brown Fox Jumped a Fence I also would like that when there are multiple space, I first delete the spaces and leave just one space rather than deleting the next word. Sent: Thursday, October 15, 2020 at 10:25 PM From: "Harald Jörg" <haj@posteo.de> To: "Christopher Dimech" <dimech@gmx.com> Cc: "Help Gnu Emacs" <help-gnu-emacs@gnu.org> Subject: Re: Deleting a word using keybinding On 10/15/20 8:44 PM, Christopher Dimech wrote: > I have updated my function to kill words forward so that even if I am > in the middle of a word that word will be killed. I also consider that > if there are multiple spaces, I delete just the spaces spaces but not > next word. This isn't exactly what the function does: If there are two or more spaces between words, then only spaces to the right of point are deleted. Also, when you delete _all_ spaces, you merge two words into one. This is the cause for your observation: > I am finding a problem however when deleting part of a sentence by > contiuing to press C--<delete> because when the point happens to be > between two words, I end up with the two words stuck together (the > previous and thn forward), which deletes the two words when I hit > C-<delete> again. It really pays off when you spend the effort to write down how you want the function to behave in all relevant situations. It is good practice to have a docstring for your command anyway, and you might detect contradictory requirements before you start writing the function. If point is before a whitespace character, you could either do nothing, or delete the previous, or delete the following word, all of them make some sense. Deleting whitespace seems somewhat unrelated. There still are cases where your function does not what you seem to expect: If the text in the buffer is "foo bar", and point is before the "a" in "bar", then executing M-x kill-spacword kills "foo". -- Cheers, haj ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Deleting a word using keybinding 2020-10-15 20:59 ` Christopher Dimech @ 2020-10-15 21:06 ` Thien-Thi Nguyen 2020-10-15 21:14 ` Christopher Dimech 0 siblings, 1 reply; 15+ messages in thread From: Thien-Thi Nguyen @ 2020-10-15 21:06 UTC (permalink / raw) To: Christopher Dimech; +Cc: Help Gnu Emacs [-- Attachment #1: Type: text/plain, Size: 565 bytes --] () Christopher Dimech <dimech@gmx.com> () Thu, 15 Oct 2020 22:59:29 +0200 and leave just one space rather than [...] There's a command for that -- can you guess its name? :-D -- Thien-Thi Nguyen ----------------------------------------------- (defun responsep (query) ; (2020) Software Libero (pcase (context query) ; = Dissenso Etico (`(technical ,ml) (correctp ml)) ...)) 748E A0E8 1CB8 A748 9BFA --------------------------------------- 6CE4 6703 2224 4C80 7502 [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 219 bytes --] ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Deleting a word using keybinding 2020-10-15 21:06 ` Thien-Thi Nguyen @ 2020-10-15 21:14 ` Christopher Dimech 2020-10-15 21:22 ` Christopher Dimech 2020-10-15 21:24 ` Stephen Berman 0 siblings, 2 replies; 15+ messages in thread From: Christopher Dimech @ 2020-10-15 21:14 UTC (permalink / raw) To: Thien-Thi Nguyen; +Cc: Help Gnu Emacs Got it (just-one-space) Sent: Thursday, October 15, 2020 at 11:06 PM From: "Thien-Thi Nguyen" <ttn@gnuvola.org> To: "Christopher Dimech" <dimech@gmx.com> Cc: "Help Gnu Emacs" <help-gnu-emacs@gnu.org> Subject: Re: Deleting a word using keybinding () Christopher Dimech <dimech@gmx.com> () Thu, 15 Oct 2020 22:59:29 +0200 and leave just one space rather than [...] There's a command for that -- can you guess its name? :-D -- Thien-Thi Nguyen ----------------------------------------------- (defun responsep (query) ; (2020) Software Libero (pcase (context query) ; = Dissenso Etico (`(technical ,ml) (correctp ml)) ...)) 748E A0E8 1CB8 A748 9BFA --------------------------------------- 6CE4 6703 2224 4C80 7502 ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Deleting a word using keybinding 2020-10-15 21:14 ` Christopher Dimech @ 2020-10-15 21:22 ` Christopher Dimech 2020-10-15 21:27 ` Drew Adams 2020-10-15 21:24 ` Stephen Berman 1 sibling, 1 reply; 15+ messages in thread From: Christopher Dimech @ 2020-10-15 21:22 UTC (permalink / raw) To: Christopher Dimech; +Cc: Help Gnu Emacs, Thien-Thi Nguyen Is there a way to detect end of buffer? Sent: Thursday, October 15, 2020 at 11:14 PM From: "Christopher Dimech" <dimech@gmx.com> To: "Thien-Thi Nguyen" <ttn@gnuvola.org> Cc: "Help Gnu Emacs" <help-gnu-emacs@gnu.org> Subject: Re: Deleting a word using keybinding Got it (just-one-space) Sent: Thursday, October 15, 2020 at 11:06 PM From: "Thien-Thi Nguyen" <ttn@gnuvola.org> To: "Christopher Dimech" <dimech@gmx.com> Cc: "Help Gnu Emacs" <help-gnu-emacs@gnu.org> Subject: Re: Deleting a word using keybinding () Christopher Dimech <dimech@gmx.com> () Thu, 15 Oct 2020 22:59:29 +0200 and leave just one space rather than [...] There's a command for that -- can you guess its name? :-D -- Thien-Thi Nguyen ----------------------------------------------- (defun responsep (query) ; (2020) Software Libero (pcase (context query) ; = Dissenso Etico (`(technical ,ml) (correctp ml)) ...)) 748E A0E8 1CB8 A748 9BFA --------------------------------------- 6CE4 6703 2224 4C80 7502 ^ permalink raw reply [flat|nested] 15+ messages in thread
* RE: Deleting a word using keybinding 2020-10-15 21:22 ` Christopher Dimech @ 2020-10-15 21:27 ` Drew Adams 2020-10-15 21:48 ` Christopher Dimech 0 siblings, 1 reply; 15+ messages in thread From: Drew Adams @ 2020-10-15 21:27 UTC (permalink / raw) To: Christopher Dimech; +Cc: Help Gnu Emacs, Thien-Thi Nguyen > Is there a way to detect end of buffer? Function `eobp' ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: RE: Deleting a word using keybinding 2020-10-15 21:27 ` Drew Adams @ 2020-10-15 21:48 ` Christopher Dimech 0 siblings, 0 replies; 15+ messages in thread From: Christopher Dimech @ 2020-10-15 21:48 UTC (permalink / raw) To: Drew Adams; +Cc: Help Gnu Emacs, Thien-Thi Nguyen I have made some imporvement. Been using the following text for testing, and when I am getting a comma, dash, or period, the function is deleting backwards. When this happens I just want it to behave as (kill-word) ;; This buffer is for text that is not saved, and for Lisp evaluation. ;; To create a file, visit it with C-x C-f and enter text in its buffer. (defun kill-spacword () "Kills Word forward including Current Word. Multiple Spaces are reduced to one space, but without deleting next word." (interactive) (if (looking-at "[ \t\n]") ;; Space detected. (progn (forward-char) (if (looking-at "[ \t\n]") (just-one-space) (progn (backward-char) (kill-word 1) ) ) ) ;; Current Point found on a word ( progn (if (eobp) nil ;;(progn (backward-word) (kill-word 1)) (progn (backward-char) (if (looking-at "[ \t\n]") (kill-word 1) (progn (backward-word) (kill-word 1)) ) ) ) ) ) ) Sent: Thursday, October 15, 2020 at 11:27 PM From: "Drew Adams" <drew.adams@oracle.com> To: "Christopher Dimech" <dimech@gmx.com> Cc: "Help Gnu Emacs" <help-gnu-emacs@gnu.org>, "Thien-Thi Nguyen" <ttn@gnuvola.org> Subject: RE: Deleting a word using keybinding > Is there a way to detect end of buffer? Function `eobp' ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Deleting a word using keybinding 2020-10-15 21:14 ` Christopher Dimech 2020-10-15 21:22 ` Christopher Dimech @ 2020-10-15 21:24 ` Stephen Berman 1 sibling, 0 replies; 15+ messages in thread From: Stephen Berman @ 2020-10-15 21:24 UTC (permalink / raw) To: Christopher Dimech; +Cc: Help Gnu Emacs, Thien-Thi Nguyen On Thu, 15 Oct 2020 23:14:05 +0200 Christopher Dimech <dimech@gmx.com> wrote: > Got it (just-one-space) > > Sent: Thursday, October 15, 2020 at 11:06 PM > From: "Thien-Thi Nguyen" <ttn@gnuvola.org> > To: "Christopher Dimech" <dimech@gmx.com> > Cc: "Help Gnu Emacs" <help-gnu-emacs@gnu.org> > Subject: Re: Deleting a word using keybinding > () Christopher Dimech <dimech@gmx.com> > () Thu, 15 Oct 2020 22:59:29 +0200 > and leave just one space rather than [...] > There's a command for that -- can you guess its name? :-D You also might find bounds-of-thing-at-point useful for your function. Steve Berman ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Deleting a word using keybinding 2020-10-15 10:26 Deleting a word using keybinding Christopher Dimech 2020-10-15 11:10 ` Jeremie Juste 2020-10-15 11:20 ` Harald Jörg @ 2020-10-15 11:34 ` Stephen Berman 2020-10-15 13:48 ` Stefan Monnier 3 siblings, 0 replies; 15+ messages in thread From: Stephen Berman @ 2020-10-15 11:34 UTC (permalink / raw) To: Christopher Dimech; +Cc: Help Gnu Emacs On Thu, 15 Oct 2020 12:26:59 +0200 Christopher Dimech <dimech@gmx.com> wrote: > I am trying to delete a word using keybinding string "C-<tab>" but the > Chord is still showing as undefined. > > I would like to delete a word even if I happen to be in the middle of > it., so I move backward. > > Here is the function > > ( global-set-key (kbd "C-<tab>" ) > ( lambda () (interactive) > ( (backward-word) > (kill-word 1) > ) > ) > ) Other have already shown how to correct your code, but here's some advice with which you can maybe help yourself in future: When I evaluate this code and then type `C-<tab>', I see this message: "Invalid function: (backward-word)". That tells you what the problem is. If you don't understand it, try reading the node "Run a Program" in the Info manual "An Introduction to Programming in Emacs Lisp", which you can access by putting the cursor after the closing parenthesis of the following expression and typing `C-x C-e': (info "(eintr) Run a Program") In particular, this part of the node should help you see the problem with your code: The single apostrophe, ‘'’, that I put in front of some of the example lists in preceding sections is called a “quote”; when it precedes a list, it tells Lisp to do nothing with the list, other than take it as it is written. But if there is no quote preceding a list, the first item of the list is special: it is a command for the computer to obey. (In Lisp, these commands are called _functions_.) The list ‘(+ 2 2)’ shown above did not have a quote in front of it, so Lisp understands that the ‘+’ is an instruction to do something with the rest of the list: add the numbers that follow. Steve Berman ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Deleting a word using keybinding 2020-10-15 10:26 Deleting a word using keybinding Christopher Dimech ` (2 preceding siblings ...) 2020-10-15 11:34 ` Stephen Berman @ 2020-10-15 13:48 ` Stefan Monnier 3 siblings, 0 replies; 15+ messages in thread From: Stefan Monnier @ 2020-10-15 13:48 UTC (permalink / raw) To: help-gnu-emacs > I am trying to delete a word using keybinding string "C-<tab>" but the > Chord is still showing as undefined. Try `C-h k C-TAB` and show us what it says. Stefan ^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2020-10-15 21:48 UTC | newest] Thread overview: 15+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2020-10-15 10:26 Deleting a word using keybinding Christopher Dimech 2020-10-15 11:10 ` Jeremie Juste 2020-10-15 11:20 ` Harald Jörg 2020-10-15 16:44 ` Christopher Dimech 2020-10-15 18:44 ` Christopher Dimech 2020-10-15 20:25 ` Harald Jörg 2020-10-15 20:59 ` Christopher Dimech 2020-10-15 21:06 ` Thien-Thi Nguyen 2020-10-15 21:14 ` Christopher Dimech 2020-10-15 21:22 ` Christopher Dimech 2020-10-15 21:27 ` Drew Adams 2020-10-15 21:48 ` Christopher Dimech 2020-10-15 21:24 ` Stephen Berman 2020-10-15 11:34 ` Stephen Berman 2020-10-15 13:48 ` Stefan Monnier
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.