Coder Social home page Coder Social logo

Comments (7)

vspinu avatar vspinu commented on July 19, 2024

Thanks for this. Unfortunately it will not work except with markdown due to the hardcoded regexp. I will fix it once I am back to full force polymode development during the Christmas vacation.

from polymode.

r2evans avatar r2evans commented on July 19, 2024

I suspected as such. I'm hoping the regexp can be predefined, perhaps like:

(defun polymode-mark-or-extend-chunk ()
   "Put point at the beginning of this chunk (assuming we are in a chunk), mark at the end. The chunk marked is the one that contains the point."
   (interactive)
   (let ((reStart (cond ((eq this-mode "markdown") "^\\(```\\|<<\\)")
                        ((eq this-mode "somethingelse") "foobar2")
                        (t "QWER")))
         (reStop (cond ((eq this-mode "markdown") "^\\(```\\|@\\)\\s-*$")
                       ((eq this-mode "somethingelse") "foobar")
                       (t "XYZ"))))
     (re-search-forward reStop)
     (move-beginning-of-line nil)
     (push-mark nil t t)
     (re-search-backward reStart)
     (move-beginning-of-line 2)))

(Obviously, my (eq ...) code is symbolic not correct code.) Not trying to push your work on it, just trying to help. Thanks!

from polymode.

vspinu avatar vspinu commented on July 19, 2024

Polymode is generic at its core and chunk management is isolated from the particulars of specific polymodes. In your case you should use the wrapper pm-get-innermost-span or the direct method for the current polymode object (pm-get-span pm/polymode), or current chunkmode object (pm-get-span pm/chunkmode). See pm--kill-span for an idea.

The whole story is a bit involved, see development notes if interested.

from polymode.

r2evans avatar r2evans commented on July 19, 2024

In that case, is this more appropriate?

(defun polymode-mark-or-extend-chunk ()
   "Put point at the beginning of this chunk (assuming we are in a chunk), mark at the end. The chunk marked is the one that contains the point."
  (interactive)
  (let ((span (pm/get-innermost-span)))
    (push-mark (nth 2 span) t t)
    (goto-char (+ 1 (nth 1 span)))))

This time it correctly deals with being outside a chunk as well. It seems too simple, though ... I don't know what "extending a chunk" means, so that will obviously enhance it a bit.

from polymode.

vspinu avatar vspinu commented on July 19, 2024

Yes. That's the way to go, but you are right - it's too simple. First of all it selects only the span at point, not the whole chunk. The span vs chunk terminology came about after I have created that function's stub. So it probably should be renamed into polymode-mark-or-extednchunk. Second, it doesn't deal with extension. Once the selection is in place you might want to press the same key again and extend the current region to nearby chunks. I haven't thought yet of how exactly the extension will work, but that's the original idea. In any case, your code should do what you want for now. I will include it into polymode on Christmas.

from polymode.

r2evans avatar r2evans commented on July 19, 2024

I was thinking about multiple presses as well as optional arguments (e.g., C-u or C-1) and what they would mean. I understand the concept of selecting multiple neighboring chunks, but I could not come up with a use-case where I would ever do the same thing to code- and noncode-blocks. But that's just my use-case, not the general one.

I don't understand what you mean, though, differentiating between span and chunk. Whenever I use this on my Rmd files, it correctly selects all of the text between (and not including) the chunk fences, regardless of the content itself (meaning things like blank lines don't affect it as they do mark-paragraph).

I'll look into your dev notes to better understand the difference. I admit that my elisp is weak, so I don't know if I can contribute much, but I'll give it a shot. Perhaps I'll finally do a fork and issue PRs, as those are even less work for you (if they're good enough and correct, that is).

from polymode.

vspinu avatar vspinu commented on July 19, 2024

but I could not come up with a use-case where I would ever do the same thing to code- and noncode-blocks

Copy paste it into a mail ;)

I don't understand what you mean, though, differentiating between span and chunk.

It's [here]. You are selecting a span, an uniform syntactic entity. Chunk can contain multiple spans - head, body and tail. This differentiation allows for clean generic implementation.

I'll look into your dev notes to better understand the difference. I admit that my elisp is weak, so I don't know if I can contribute much, but I'll give it a shot.

You can PR the way it is now. I will add the extension part once I figured out how I want it. Make sure that you have a clean doc string with first line a complete sentence. This is an emacs convention.

Thanks.

from polymode.

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.