all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* How to delete all text from beginning of buffer to mark
@ 2017-05-08 14:14 Angus Comber
  2017-05-08 14:20 ` Loris Bennett
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Angus Comber @ 2017-05-08 14:14 UTC (permalink / raw)
  To: help-gnu-emacs

I am in a large file of text and my cursor is at the start of the text I want.  I want to delete all the text before the cursor.  I know I can set the mark using C-sp but how do I then select to the beginning of the file?

What is the best way to basically delete all text before the cursor in the buffer?


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

* Re: How to delete all text from beginning of buffer to mark
  2017-05-08 14:14 How to delete all text from beginning of buffer to mark Angus Comber
@ 2017-05-08 14:20 ` Loris Bennett
  2017-05-08 15:21   ` tomas
  2017-05-08 15:35 ` Teemu Likonen
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 11+ messages in thread
From: Loris Bennett @ 2017-05-08 14:20 UTC (permalink / raw)
  To: help-gnu-emacs

Angus Comber <anguscomber@gmail.com> writes:

> I am in a large file of text and my cursor is at the start of the text
> I want.  I want to delete all the text before the cursor.  I know I
> can set the mark using C-sp but how do I then select to the beginning
> of the file?

M-<

maybe?

Cheers,

Loris

-- 
This signature is currently under construction.


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

* Re: How to delete all text from beginning of buffer to mark
  2017-05-08 14:20 ` Loris Bennett
@ 2017-05-08 15:21   ` tomas
  2017-05-08 15:43     ` hector
  0 siblings, 1 reply; 11+ messages in thread
From: tomas @ 2017-05-08 15:21 UTC (permalink / raw)
  To: help-gnu-emacs

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Mon, May 08, 2017 at 04:20:58PM +0200, Loris Bennett wrote:
> Angus Comber <anguscomber@gmail.com> writes:
> 
> > I am in a large file of text and my cursor is at the start of the text
> > I want.  I want to delete all the text before the cursor.  I know I
> > can set the mark using C-sp but how do I then select to the beginning
> > of the file?

Just by moving point to the beginning of the buffer (e.g. by C-M-a) The
selection is between point and mark (which you've set by C-sp)

cheers
- -- tomás
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAlkQjP4ACgkQBcgs9XrR2kbdUwCeMZnxiX5FYbYNdjl7h0TcL0Gy
sw0An21ulYbCQN1Sk7ytlk73oYurV41O
=deFO
-----END PGP SIGNATURE-----



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

* Re: How to delete all text from beginning of buffer to mark
  2017-05-08 14:14 How to delete all text from beginning of buffer to mark Angus Comber
  2017-05-08 14:20 ` Loris Bennett
@ 2017-05-08 15:35 ` Teemu Likonen
  2017-05-08 15:50 ` Yuri Khan
  2017-05-09 11:39 ` Magnus Therning
  3 siblings, 0 replies; 11+ messages in thread
From: Teemu Likonen @ 2017-05-08 15:35 UTC (permalink / raw)
  To: Angus Comber; +Cc: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 468 bytes --]

Angus Comber [2017-05-08 07:14:40-07] wrote:

> What is the best way to basically delete all text before the cursor in
> the buffer?

M-< C-w

The first command (beginning-of-buffer) sets the mark and moves the
point to the beginning of buffer. The second command (kill-region) kills
the text between the point and the mark.

-- 
/// Teemu Likonen   - .-..   <https://keybase.io/tlikonen> //
// PGP: 4E10 55DC 84E9 DFF6 13D7 8557 719D 69D3 2453 9450 ///

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 454 bytes --]

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

* Re: How to delete all text from beginning of buffer to mark
  2017-05-08 15:21   ` tomas
@ 2017-05-08 15:43     ` hector
  0 siblings, 0 replies; 11+ messages in thread
From: hector @ 2017-05-08 15:43 UTC (permalink / raw)
  To: help-gnu-emacs

On Mon, May 08, 2017 at 05:21:35PM +0200, tomas@tuxteam.de wrote:
> On Mon, May 08, 2017 at 04:20:58PM +0200, Loris Bennett wrote:
> > Angus Comber <anguscomber@gmail.com> writes:
> > 
> > > I am in a large file of text and my cursor is at the start of the text
> > > I want.  I want to delete all the text before the cursor.  I know I
> > > can set the mark using C-sp but how do I then select to the beginning
> > > of the file?
> 
> Just by moving point to the beginning of the buffer (e.g. by C-M-a) The
> selection is between point and mark (which you've set by C-sp)

Just for the sake of completeness,
The region always extends between point and the mark, no matter which
one comes earlier in the text.



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

* Re: How to delete all text from beginning of buffer to mark
  2017-05-08 14:14 How to delete all text from beginning of buffer to mark Angus Comber
  2017-05-08 14:20 ` Loris Bennett
  2017-05-08 15:35 ` Teemu Likonen
@ 2017-05-08 15:50 ` Yuri Khan
  2017-05-09  2:04   ` Emanuel Berg
  2017-05-09 11:39 ` Magnus Therning
  3 siblings, 1 reply; 11+ messages in thread
From: Yuri Khan @ 2017-05-08 15:50 UTC (permalink / raw)
  To: Angus Comber; +Cc: help-gnu-emacs@gnu.org

On Mon, May 8, 2017 at 9:14 PM, Angus Comber <anguscomber@gmail.com> wrote:

> What is the best way to basically delete all text before the cursor in the buffer?

Ctrl+Shift+Home, Del. <ducks>

* Nitpicker’s corner: This works if you are in a GUI frame and have
transient-mark-mode and delete-selection-mode enabled.



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

* Re: How to delete all text from beginning of buffer to mark
  2017-05-08 15:50 ` Yuri Khan
@ 2017-05-09  2:04   ` Emanuel Berg
  2017-05-09  2:20     ` iterating the kill ring (was: Re: How to delete all text from beginning of buffer to mark) Emanuel Berg
  2017-05-09  3:07     ` How to delete all text from beginning of buffer to mark Kaushal Modi
  0 siblings, 2 replies; 11+ messages in thread
From: Emanuel Berg @ 2017-05-09  2:04 UTC (permalink / raw)
  To: help-gnu-emacs

Yuri Khan wrote:

>> What is the best way to basically delete all
>> text before the cursor in the buffer?
>
> Ctrl+Shift+Home, Del. <ducks>
>
> * Nitpicker’s corner: This works if you are
> in a GUI frame and have transient-mark-mode
> and delete-selection-mode enabled.

I agree the *best* way to do this is to use
shortcuts. Tho not the particular ones
suggested here :)

Here is an Elisp function for the OP.
Tho shortcuts are better, because they are as
fast and in the long run generalizable, so in
the long (short) run it is much more beneficial
to acquire them for all kinds of editing.

However it can be interesting to discuss
a function:

    (defun delete-to-point ()
      (interactive)
      (let ((start 1)
            (end   (point)))
        (delete-region start end) ))

Things to note: at the beginning of the buffer,
point is 1 (not 0).

Also, there is a difference between deleting
and killing. In general, I suppose it is wiser
to kill because then the kill ring holds it
(check out `kill-region').

Won't that fill up the kill ring with stuff you
won't need? Yes, but once you learn how to
iterate the kill ring back and forth, that
doesn't matter.

-- 
underground experts united
http://user.it.uu.se/~embe8573




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

* iterating the kill ring (was: Re: How to delete all text from beginning of buffer to mark)
  2017-05-09  2:04   ` Emanuel Berg
@ 2017-05-09  2:20     ` Emanuel Berg
  2017-05-09  3:07     ` How to delete all text from beginning of buffer to mark Kaushal Modi
  1 sibling, 0 replies; 11+ messages in thread
From: Emanuel Berg @ 2017-05-09  2:20 UTC (permalink / raw)
  To: help-gnu-emacs

Emanuel Berg wrote:

> Won't that fill up the kill ring with stuff
> you won't need? Yes, but once you learn how
> to iterate the kill ring back and forth, that
> doesn't matter.

How do people do this?

I have:

    (defun yank-pop-back (&optional arg)
      (interactive "*p")
      (yank-pop (if arg (* arg -1) -1)) )

With `yank' at C-y, `yank-pop' at M-y, and then
the "yank-pop-back" above as C-M-y, it is very
easy to yank and then iterate back and forth.

The elaborate stuff with ARG isn't needed to
use with the setup I just described.
However remove it, it won't work iterating back
and forth!

    (error "Previous command was not a yank") in yank-pop

Must be an interface mismatch?

Hey, if it works, don't fix it, right :)

-- 
underground experts united
http://user.it.uu.se/~embe8573




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

* Re: How to delete all text from beginning of buffer to mark
  2017-05-09  2:04   ` Emanuel Berg
  2017-05-09  2:20     ` iterating the kill ring (was: Re: How to delete all text from beginning of buffer to mark) Emanuel Berg
@ 2017-05-09  3:07     ` Kaushal Modi
  2017-05-09  6:53       ` Emanuel Berg
  1 sibling, 1 reply; 11+ messages in thread
From: Kaushal Modi @ 2017-05-09  3:07 UTC (permalink / raw)
  To: Help Gnu Emacs mailing list

>
> However it can be interesting to discuss
> a function:
>
>     (defun delete-to-point ()
>       (interactive)
>       (let ((start 1)
>             (end   (point)))
>         (delete-region start end) ))
>

For safety, I would set the start to (point-min) instead of 1. Then if the
user has narrowed the buffer, the deletion will begin only from the
beginning of the narrowed region, instead of the actual beginning of the
buffer.

> --

Kaushal Modi


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

* Re: How to delete all text from beginning of buffer to mark
  2017-05-09  3:07     ` How to delete all text from beginning of buffer to mark Kaushal Modi
@ 2017-05-09  6:53       ` Emanuel Berg
  0 siblings, 0 replies; 11+ messages in thread
From: Emanuel Berg @ 2017-05-09  6:53 UTC (permalink / raw)
  To: help-gnu-emacs

Kaushal Modi wrote:

> For safety, I would set the start to
> (point-min) instead of 1. Then if the user
> has narrowed the buffer, the deletion will
> begin only from the beginning of the narrowed
> region, instead of the actual beginning of
> the buffer.

You are right! Nice catch. Myself I never use
narrowing but that's no excuse writing code
that isn't sound ("movable" in this case).

-- 
underground experts united
http://user.it.uu.se/~embe8573




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

* Re: How to delete all text from beginning of buffer to mark
  2017-05-08 14:14 How to delete all text from beginning of buffer to mark Angus Comber
                   ` (2 preceding siblings ...)
  2017-05-08 15:50 ` Yuri Khan
@ 2017-05-09 11:39 ` Magnus Therning
  3 siblings, 0 replies; 11+ messages in thread
From: Magnus Therning @ 2017-05-09 11:39 UTC (permalink / raw)
  To: Angus Comber; +Cc: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 839 bytes --]


Angus Comber <anguscomber@gmail.com> writes:

> I am in a large file of text and my cursor is at the start of the text
> I want. I want to delete all the text before the cursor. I know I can
> set the mark using C-sp but how do I then select to the beginning of
> the file?
>
> What is the best way to basically delete all text before the cursor in
> the buffer?

In Evil mode this one way to do it: `d 0 k d gg` ;)

If you the text you want is at the start of a line you can skip the
initial `d 0`.

/M

--
Magnus Therning              OpenPGP: 0x927912051716CE39
email: magnus@therning.org   jabber: magnus@therning.org
twitter: magthe               http://therning.org/magnus

Some people, when confronted with a problem, think,
“I know, I’ll use MySQL.” Now their problem is a single point of
failure.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

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

end of thread, other threads:[~2017-05-09 11:39 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-08 14:14 How to delete all text from beginning of buffer to mark Angus Comber
2017-05-08 14:20 ` Loris Bennett
2017-05-08 15:21   ` tomas
2017-05-08 15:43     ` hector
2017-05-08 15:35 ` Teemu Likonen
2017-05-08 15:50 ` Yuri Khan
2017-05-09  2:04   ` Emanuel Berg
2017-05-09  2:20     ` iterating the kill ring (was: Re: How to delete all text from beginning of buffer to mark) Emanuel Berg
2017-05-09  3:07     ` How to delete all text from beginning of buffer to mark Kaushal Modi
2017-05-09  6:53       ` Emanuel Berg
2017-05-09 11:39 ` Magnus Therning

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.