Comments (7)
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.
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.
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.
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.
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.
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.
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)
- Help with a (hopefully) simple polymode?
- Reproducible error: stuck in latex-mode
- Starting polymode with lsp, makes the cursor to jump to the end of buffer HOT 10
- can't find polymode via package-install? HOT 1
- electric-indent-mode
- How to run a function is indirect buffers with the same major mode only?
- Typescript-xml polymode
- Setting mode file local variable to polymode applies itself recursively infinitely until cancelled
- Background Adjustment when Background Unspecified
- polymode creates additional [web] buffer
- Interaction with nix-mode: font-lock broken HOT 4
- Chunks not following automatic Emacs switch to light/dark theme HOT 5
- Polymode, Poly-COMEEGA and COMEEGA (Collaborative Org Mode Enhanced Emacs Generalized Authorship)
- inner mode indentation not works on the first line after head mark
- org-mode links become invisible HOT 3
- Polymode does not work in org-edit-special
- eglot sees the whole outer buffer content HOT 3
- hs-hide-all gives unbalanced parentheses error when it shouldn't in some Rnw buffers
- Inconsistent font size in heads
- Beginning of the Polymode buffer is ignored by flymake HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from polymode.