Giter Site home page Giter Site logo

kill region or current line about lem HOT 4 OPEN

timmydo avatar timmydo commented on June 11, 2024
kill region or current line

from lem.

Comments (4)

timmydo avatar timmydo commented on June 11, 2024 1

Is it just me or do things stop working after a couple of kill-regions? After I killed a region with a mark, I don't see a mark anymore but when I wipe it kills an unexpected region of text. I was also using undo so it's possible it got confused there.

from lem.

Sasanidas avatar Sasanidas commented on June 11, 2024

I think this may work:

(define-command kill-region-or-line () ()
  "Kill the text of region or the current line if no region."
  (if (buffer-mark (current-buffer))
        (kill-region (region-beginning)
                     (region-end))
        (and (line-start (current-point))
             (kill-whole-line))))

Keep in mind that this doesn't work with the vi-mode visual line, mostly because it doesn't uses the emacs-mode mark

from lem.

cxxxr avatar cxxxr commented on June 11, 2024

I also wrote.

(defmethod execute :around (mode (command kill-region) argument)
  (if (buffer-mark-p (current-buffer))
      (call-next-method)
      (with-point ((start (current-point))
                   (end (current-point)))
        (line-start start)
        (line-offset end 1)
        (kill-region start end))))

from lem.

timmydo avatar timmydo commented on June 11, 2024

Thanks

@Sasanidas your implementation causes the cursor to move up after kiling the line. Also the killed line doesn't include the newline character.

@cxxxr I think your implementation has the same issue as mine where it wouldn't kill the last line in the buffer. I didn't know about execute :around. That's pretty neat.

I wrote another implementation but need to fine tune it because it doesn't work with the first line in the buffer.

from lem.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.