* delete buffer content from the point
@ 2021-07-13 11:32 Luca Ferrari
2021-07-13 11:40 ` Tassilo Horn
` (6 more replies)
0 siblings, 7 replies; 12+ messages in thread
From: Luca Ferrari @ 2021-07-13 11:32 UTC (permalink / raw)
To: help-gnu-emacs
Is there a short and sweet way to kill the content of the current
buffer from the point to the end of the buffer itself?
I do often duplicate files and adjusts the header part, then I do
'C-k' until the part of the file I want to delete has disappeared, but
this has the drawback of being slow and inserting a wall of text into
the kill ring.
Thanks,
Luca
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: delete buffer content from the point
2021-07-13 11:32 delete buffer content from the point Luca Ferrari
@ 2021-07-13 11:40 ` Tassilo Horn
2021-07-13 11:44 ` Philip Kaludercic
` (5 subsequent siblings)
6 siblings, 0 replies; 12+ messages in thread
From: Tassilo Horn @ 2021-07-13 11:40 UTC (permalink / raw)
To: Luca Ferrari; +Cc: help-gnu-emacs
Luca Ferrari <fluca1978@gmail.com> writes:
> Is there a short and sweet way to kill the content of the current
> buffer from the point to the end of the buffer itself?
> I do often duplicate files and adjusts the header part, then I do
> 'C-k' until the part of the file I want to delete has disappeared, but
> this has the drawback of being slow and inserting a wall of text into
> the kill ring.
The following should do the trick. Bind it to a key of your liking.
--8<---------------cut here---------------start------------->8---
(defun my/delete-from-point-to-end ()
(interactive)
;; Or kill-region if you want the text in the kill-ring.
;; Maybe (1+ (point)) if you don't want the char at point to be removed.
(delete-region (point) (buffer-end 1)))
--8<---------------cut here---------------end--------------->8---
Bye,
Tassilo
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: delete buffer content from the point
2021-07-13 11:32 delete buffer content from the point Luca Ferrari
2021-07-13 11:40 ` Tassilo Horn
@ 2021-07-13 11:44 ` Philip Kaludercic
2021-07-13 11:51 ` Robert Pluim
2021-07-13 11:49 ` Emanuel Berg via Users list for the GNU Emacs text editor
` (4 subsequent siblings)
6 siblings, 1 reply; 12+ messages in thread
From: Philip Kaludercic @ 2021-07-13 11:44 UTC (permalink / raw)
To: Luca Ferrari; +Cc: help-gnu-emacs
Luca Ferrari <fluca1978@gmail.com> writes:
> Is there a short and sweet way to kill the content of the current
> buffer from the point to the end of the buffer itself?
> I do often duplicate files and adjusts the header part, then I do
> 'C-k' until the part of the file I want to delete has disappeared, but
> this has the drawback of being slow and inserting a wall of text into
> the kill ring.
With the default keys, you could probably do something like
C-SPC mark the current position
M-> go to the end of the buffer
C-w kill the region
but if you want to declare your own function
(defun local/delete-rest-of-buffer ()
"Delete the buffer contents from the point onwards."
(delete-region (point) (point-max)))
would probably do the job, without having to append the region to the
kill ring.
> Thanks,
> Luca
--
Philip Kaludercic
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: delete buffer content from the point
2021-07-13 11:32 delete buffer content from the point Luca Ferrari
2021-07-13 11:40 ` Tassilo Horn
2021-07-13 11:44 ` Philip Kaludercic
@ 2021-07-13 11:49 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-07-13 11:49 ` Óscar Fuentes
` (3 subsequent siblings)
6 siblings, 0 replies; 12+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-07-13 11:49 UTC (permalink / raw)
To: help-gnu-emacs
Luca Ferrari wrote:
> Is there a short and sweet way to kill the content of the
> current buffer from the point to the end of the buffer
> itself? I do often duplicate files and adjusts the header
> part, then I do 'C-k' until the part of the file I want to
> delete has disappeared, but this has the drawback of being
> slow and inserting a wall of text into the kill ring.
`delete-blank-lines'?
;;; -*- lexical-binding: t -*-
;;;
;;; this file:
;;; http://user.it.uu.se/~embe8573/emacs-init/kill.el
;;; https://dataswamp.org/~incal/emacs-init/kill.el
(setq kill-do-not-save-duplicates t)
(setq kill-whole-line t)
(setq yank-excluded-properties t)
(defun kill-line-remove-blanks ()
(interactive)
(let ((all-blanks "[[:space:]]*$"))
(if (looking-at all-blanks)
(progn
(delete-blank-lines)
(when (and (= (point-min) (point))
(looking-at all-blanks) )
(kill-line) ))
(kill-line) )))
(provide 'kill)
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: delete buffer content from the point
2021-07-13 11:32 delete buffer content from the point Luca Ferrari
` (2 preceding siblings ...)
2021-07-13 11:49 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-07-13 11:49 ` Óscar Fuentes
2021-07-13 11:50 ` Emanuel Berg via Users list for the GNU Emacs text editor
` (2 subsequent siblings)
6 siblings, 0 replies; 12+ messages in thread
From: Óscar Fuentes @ 2021-07-13 11:49 UTC (permalink / raw)
To: Luca Ferrari; +Cc: help-gnu-emacs
Luca Ferrari <fluca1978@gmail.com> writes:
> Is there a short and sweet way to kill the content of the current
> buffer from the point to the end of the buffer itself?
> I do often duplicate files and adjusts the header part, then I do
> 'C-k' until the part of the file I want to delete has disappeared, but
> this has the drawback of being slow and inserting a wall of text into
> the kill ring.
Set the mark with C-SPC, move to the end of buffer with C-<end>, M-x
delete-region.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: delete buffer content from the point
2021-07-13 11:32 delete buffer content from the point Luca Ferrari
` (3 preceding siblings ...)
2021-07-13 11:49 ` Óscar Fuentes
@ 2021-07-13 11:50 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-07-13 12:08 ` Joost Kremers
2021-07-13 13:40 ` [External] : " Drew Adams
6 siblings, 0 replies; 12+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-07-13 11:50 UTC (permalink / raw)
To: help-gnu-emacs
Luca Ferrari wrote:
> Is there a short and sweet way to kill the content of the current
> buffer from the point to the end of the buffer itself?
> I do often duplicate files and adjusts the header part, then I do
> 'C-k' until the part of the file I want to delete has disappeared, but
> this has the drawback of being slow and inserting a wall of text into
> the kill ring.
Or `delete-region':
(delete-region (point) (point-max))
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: delete buffer content from the point
2021-07-13 11:44 ` Philip Kaludercic
@ 2021-07-13 11:51 ` Robert Pluim
0 siblings, 0 replies; 12+ messages in thread
From: Robert Pluim @ 2021-07-13 11:51 UTC (permalink / raw)
To: Philip Kaludercic; +Cc: Luca Ferrari, help-gnu-emacs
>>>>> On Tue, 13 Jul 2021 11:44:57 +0000, Philip Kaludercic <philipk@posteo.net> said:
Philip> (defun local/delete-rest-of-buffer ()
Philip> "Delete the buffer contents from the point onwards."
Philip> (delete-region (point) (point-max)))
Philip> would probably do the job, without having to append the region to the
Philip> kill ring.
Note that this will not delete to the end of the buffer if narrowing
is in effect; you'd need to throw in a (widen) for that.
Robert
--
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: delete buffer content from the point
2021-07-13 11:32 delete buffer content from the point Luca Ferrari
` (4 preceding siblings ...)
2021-07-13 11:50 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-07-13 12:08 ` Joost Kremers
2021-07-14 8:45 ` Luca Ferrari
2021-07-13 13:40 ` [External] : " Drew Adams
6 siblings, 1 reply; 12+ messages in thread
From: Joost Kremers @ 2021-07-13 12:08 UTC (permalink / raw)
To: Luca Ferrari; +Cc: help-gnu-emacs
On Tue, Jul 13 2021, Luca Ferrari wrote:
> Is there a short and sweet way to kill the content of the current
> buffer from the point to the end of the buffer itself?
> I do often duplicate files and adjusts the header part, then I do
> 'C-k' until the part of the file I want to delete has disappeared, but
> this has the drawback of being slow and inserting a wall of text into
> the kill ring.
C-SPC to set the mark, M-> to go to the end of the buffer and then DEL or
BACKSPACE or C-d or C-w to delete the text.
But for the use-case that you describe, it may be more practical to use
`auto-insert-mode` or yasnippet.
--
Joost Kremers
Life has its moments
^ permalink raw reply [flat|nested] 12+ messages in thread
* RE: [External] : delete buffer content from the point
2021-07-13 11:32 delete buffer content from the point Luca Ferrari
` (5 preceding siblings ...)
2021-07-13 12:08 ` Joost Kremers
@ 2021-07-13 13:40 ` Drew Adams
2021-07-30 10:49 ` Luca Ferrari
6 siblings, 1 reply; 12+ messages in thread
From: Drew Adams @ 2021-07-13 13:40 UTC (permalink / raw)
To: Luca Ferrari, help-gnu-emacs
> Is there a short and sweet way to kill the content of the current
> buffer from the point to the end of the buffer itself?
What everyone else has said - `delete-region'.
But don't forget also `flush-lines', which can
do this or delete only some of the lines. It
acts from point forward. (Also `keep-lines'.)
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: delete buffer content from the point
2021-07-13 12:08 ` Joost Kremers
@ 2021-07-14 8:45 ` Luca Ferrari
0 siblings, 0 replies; 12+ messages in thread
From: Luca Ferrari @ 2021-07-14 8:45 UTC (permalink / raw)
To: Joost Kremers; +Cc: help-gnu-emacs
On Tue, Jul 13, 2021 at 2:11 PM Joost Kremers <joostkremers@fastmail.fm> wrote:
> But for the use-case that you describe, it may be more practical to use
> `auto-insert-mode` or yasnippet.
I do use yasnippet, but sometimes I don't have access to it (e.g., a
machine I log in only once and has vanilla emacs).
That's why I was looking for a more simple way that can help me in
those occasions.
Thanlk you all for pointing me to delete-region.
Luca
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [External] : delete buffer content from the point
2021-07-13 13:40 ` [External] : " Drew Adams
@ 2021-07-30 10:49 ` Luca Ferrari
2021-07-30 15:59 ` Drew Adams
0 siblings, 1 reply; 12+ messages in thread
From: Luca Ferrari @ 2021-07-30 10:49 UTC (permalink / raw)
To: Drew Adams; +Cc: help-gnu-emacs
On Tue, Jul 13, 2021 at 3:40 PM Drew Adams <drew.adams@oracle.com> wrote:
>
> > Is there a short and sweet way to kill the content of the current
> > buffer from the point to the end of the buffer itself?
>
> What everyone else has said - `delete-region'.
>
> But don't forget also `flush-lines', which can
Uhm..flush-lines is really interesting, I've bound as follows:
(bind-key (kbd "C-S-k") ( lambda()
(interactive)
(flush-lines ".*") ) )
Thanks!
Luca
^ permalink raw reply [flat|nested] 12+ messages in thread
* RE: [External] : delete buffer content from the point
2021-07-30 10:49 ` Luca Ferrari
@ 2021-07-30 15:59 ` Drew Adams
0 siblings, 0 replies; 12+ messages in thread
From: Drew Adams @ 2021-07-30 15:59 UTC (permalink / raw)
To: Luca Ferrari; +Cc: help-gnu-emacs
> > But don't forget also `flush-lines'
>
> Uhm..flush-lines is really interesting, I've bound as follows:
>
> (bind-key (kbd "C-S-k") ( lambda()
> (interactive)
> (flush-lines ".*") ) )
Don't forget too that you can use `flush-lines'
and `keep-lines' in buffers, such as `M-x grep'
output, after using `C-x C-q' to enable editing.
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2021-07-30 15:59 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-07-13 11:32 delete buffer content from the point Luca Ferrari
2021-07-13 11:40 ` Tassilo Horn
2021-07-13 11:44 ` Philip Kaludercic
2021-07-13 11:51 ` Robert Pluim
2021-07-13 11:49 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-07-13 11:49 ` Óscar Fuentes
2021-07-13 11:50 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-07-13 12:08 ` Joost Kremers
2021-07-14 8:45 ` Luca Ferrari
2021-07-13 13:40 ` [External] : " Drew Adams
2021-07-30 10:49 ` Luca Ferrari
2021-07-30 15:59 ` Drew Adams
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).