all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* alt to copy-region-as-kill for kill ring
@ 2021-03-07  8:57 Jeremie Juste
  2021-03-07  9:43 ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 6+ messages in thread
From: Jeremie Juste @ 2021-03-07  8:57 UTC (permalink / raw)
  To: help-gnu-emacs

Hello,

The following function to copies a word in the visible buffer and comes
back to point to yank it. It builds on avy package.


(defun boomrang (query-char)
  "kill word and come back to point"
  (interactive (list (read-char "Query Char:")))
  (save-excursion
    (progn
      (avy-goto-word-1 query-char)      
      (copy-region-as-kill (point) (progn (re-search-forward "[[:alnum:]_-]*") (point)))))
  (yank))


There are a few limitations to it:
-  if the word is in a different buffer it yank it but the cursor does
not come back
-  If we bind the function to a key (say C-'), it is rather difficult to control the copy-region-as-kill as when
used with this function it behaves like C-M-w (see function kill-ring-save).

for instance (cursor position is represented as a |)
|dfd ## M-d C-' (Query-char i) ==> dfdinstance

when only instance is wanted. A temporary solution might be to enter a
key between after M-d to deactivate appending. But this solution is
costly.

Do you have an better solution?

Best regards,
-- 
Jeremie Juste



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

* Re: alt to copy-region-as-kill for kill ring
  2021-03-07  8:57 alt to copy-region-as-kill for kill ring Jeremie Juste
@ 2021-03-07  9:43 ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-03-07 10:35   ` Jeremie Juste
  0 siblings, 1 reply; 6+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-03-07  9:43 UTC (permalink / raw)
  To: help-gnu-emacs

Jeremie Juste wrote:

> The following function to copies a word in the visible
> buffer and comes back to point to yank it. It builds on
> avy package.

OK, it should be required, then (require 'avy) - hm...

Ah, it is in both ELPA (0.5.0) and MELPA (20201226.1734),
actually! And then tons of extra avy-material at that.

> (defun boomrang (query-char)
>   "kill word and come back to point"

geh.el:281: First sentence should end with punctuation
geh.el:281: First line should be capitalized
geh.el:281: Argument ‘query-char’ should appear (as QUERY-CHAR) in the doc string

Please use this: [check-package-style, lines 50-62)
  https://dataswamp.org/~incal/emacs-init/ide/elisp.el

> (interactive (list (read-char "Query Char:")))

Should be equivalent?

  (interactive "cchar: ")

> (save-excursion

If mark moves as well, one can consider
`save-mark-and-excursion'. I actually don't know if it does,
do you? And I don't know a good way to find out, either.
But OTOH, why not just reset as much of the initial state as
possible? Because the state is disorganized bureaucracy?
Because it is the PO-LICE department? ... well, no! I think
one can just reset it while at it.

> (progn

not needed, right?

>       (copy-region-as-kill (point)

> (progn (re-search-forward "[[:alnum:]_-]*") (point))

This will signal an error if there is no hit. One can instead
do (when (re-search-forward RE (point-max) t) (point)).
And speaking of the RE, isn't "[[:alnum:]_-]*" always
found, instantly? You want

  (re-search-forward "[[:alnum:]_-]+")

or something else?

> There are a few limitations to it: - if the word is in
> a different buffer it yank it but the cursor does

`save-window-excursion'?

> - If we bind the function to a key (say C-'), it is rather
> difficult to control the copy-region-as-kill as when used
> with this function it behaves like C-M-w (see function
> kill-ring-save).

?

You can bind it to whatever, it doesn't change it or
anything else.

> when only instance is wanted. A temporary solution might be
> to enter a key between after M-d to deactivate appending.
> But this solution is costly.

?

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal




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

* Re: alt to copy-region-as-kill for kill ring
  2021-03-07  9:43 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-03-07 10:35   ` Jeremie Juste
  2021-03-07 14:42     ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 6+ messages in thread
From: Jeremie Juste @ 2021-03-07 10:35 UTC (permalink / raw)
  To: help-gnu-emacs

Hello Emanuel,

|| > On Sunday,  7 Mar 2021 at 10:43, Emanuel Berg via Users list for the GNU Emacs text editor wrote:
|| >> Jeremie Juste wrote:
Many thanks for your suggestions. My coding style needs improvement and
I will use checkdoc-defun from now on. You are right about the RE as well.

The function has greatly improved,

(require 'avy) # available on MELPA
(defun boomrang (query-char)
   "Kill word and come back to point.
 Argument QUERY-CHAR The first character of the word to be copied."
   (interactive "cchar: Query Char:")
  (save-window-excursion
    (avy-goto-word-1 query-char)      
    (copy-region-as-kill (point) (when (re-search-forward "[[:alnum:]_-]+" (point-max) t) (point))))
  (yank))
  
> OK, it should be required, then (require 'avy) - hm...
avy has indeed many tools for copying lines and regions, which I happily
use, but I didn't any suggestions for words.


>> There are a few limitations to it: - if the word is in
>> a different buffer it yank it but the cursor does
>
> `save-window-excursion'?
It did solve this problem thanks.


>> - If we bind the function to a key (say C-'), it is rather
>> difficult to control the copy-region-as-kill as when used
>> with this function it behaves like C-M-w (see function
>> kill-ring-save).

When I use boomrang just after I killed something, I get the same behavior
as one would use  C-M-w (append-next-kill &optional INTERACTIVE). I was
look for a way to bypass this append-next-kill


Best regards,
Jeremie



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

* Re: alt to copy-region-as-kill for kill ring
  2021-03-07 10:35   ` Jeremie Juste
@ 2021-03-07 14:42     ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-03-07 17:11       ` Jeremie Juste
  0 siblings, 1 reply; 6+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-03-07 14:42 UTC (permalink / raw)
  To: help-gnu-emacs

Jeremie Juste wrote:

> When I use boomrang just after I killed something, I get the
> same behavior as one would use C-M-w (append-next-kill
> &optional INTERACTIVE). I was look for a way to bypass this
> append-next-kill

OK, but what would you like to happen?

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal




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

* Re: alt to copy-region-as-kill for kill ring
  2021-03-07 14:42     ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-03-07 17:11       ` Jeremie Juste
  2021-03-07 18:40         ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 6+ messages in thread
From: Jeremie Juste @ 2021-03-07 17:11 UTC (permalink / raw)
  To: help-gnu-emacs

On Sunday,  7 Mar 2021 at 15:42, Emanuel Berg via Users list for the GNU Emacs text editor wrote:
> Jeremie Juste wrote:
>
>> When I use boomrang just after I killed something, I get the
>> same behavior as one would use C-M-w (append-next-kill
>> &optional INTERACTIVE). I was look for a way to bypass this
>> append-next-kill
>
> OK, but what would you like to happen?
I don't want the function (boomrang) to use the append-next-kill feature
at all. But I don't understand what is triggering it.
If I call the function (boomrang) just after a kill-word,
the word I have just killed is appended to the result returned by
boomrang. (To reproduce the boomrang has to be binded to a key).

This is why I said that it is similar to the (append-next-kill), when
you activate append-next-kill, it only append if the very next function call
is a kill. (see the doc of (kill-ring-save BEG END &optional REGION) for
more details).

Many thanks for your patience.
Best regards,
Jeremie Juste



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

* Re: alt to copy-region-as-kill for kill ring
  2021-03-07 17:11       ` Jeremie Juste
@ 2021-03-07 18:40         ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 0 replies; 6+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-03-07 18:40 UTC (permalink / raw)
  To: help-gnu-emacs

Jeremie Juste wrote:

> I don't want the function (boomrang) to use the
> append-next-kill feature at all. But I don't understand what
> is triggering it. If I call the function (boomrang) just
> after a kill-word, the word I have just killed is appended
> to the result returned by boomrang. (To reproduce the
> boomrang has to be binded to a key).

OK, I see... maybe.

Right, but what about just reading from some buffer and
inserting then?

So it doesn't involve the kill ring and this feature?

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal




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

end of thread, other threads:[~2021-03-07 18:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-03-07  8:57 alt to copy-region-as-kill for kill ring Jeremie Juste
2021-03-07  9:43 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-03-07 10:35   ` Jeremie Juste
2021-03-07 14:42     ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-03-07 17:11       ` Jeremie Juste
2021-03-07 18:40         ` Emanuel Berg via Users list for the GNU Emacs text editor

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.