-
Notifications
You must be signed in to change notification settings - Fork 167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add some markdown specific narrow or mark commands #191
Comments
I've thought about this too. Actually, it can be done now but it is not at all straightforward. Since As you noticed, I'm planning to rethink the defun definition, as well as the section/subtree editing commands. For example, I think moving subtrees should be the default rather than moving individual headings, since probably people want the hierarchy below to remain intact. Similarly, perhaps a defun should be the full subtree (but I'm not sure if nested defuns will work in Emacs). |
I had thought about outline commands but didn't look too far. outline-mark-subtree does work, I think I'll have to commit it to memory and find it a keybinding. Maybe it deserves to be in the Markdown menu since it isn't on outline-mode or outline-minor-mode menu. I agree that in text files it's hard to find a good meaning for defun. At first I thought current section might be best, but the more I think about it, I like current subtree for it. I had looked to see if markdown-mode used pages (e.g., mark-page) for something like level 1 headings but it didn't. That's probably correct, but it might be something to consider. expand-region's support for org-mode has er/mark-org-parent which walks up sections (current section, then parent, etc.) which would be great (as would markdown-mode support for expand-region). I agree that moving subtrees should be the default, particularly since there are easy commands to pro/demote headings/subtrees. If I want something other than moving the subtree, I can first pro/demote headings as appropriate. |
For pages, I was thinking of using horizontal rules. Toplevel headings are a good idea too though. |
For what it's worth, org-mode seems to define the following in the global map:
|
Thanks—I have been working on those functions and had exactly the same keybindings in mind. I'm only holding off to test alternative defun movement commands. I have a working branch in which defuns are subtrees, as mentioned above. The implication is that defuns are no longer linear in the buffer, as in other modes. Subtrees are nested and so the movement is very different. However, for linear movement we already have the Related to that, I will be adding block movement, marking, and narrowing commands (where blocks are code blocks, blockquotes, lists, paragraphs, etc.) Also, I'm working on page-based commands, where pages are top-level headings. The built-in Emacs page commands are regexp-based, so unfortunately they won't work with Markdown when fenced code blocks are allowed and need to be re-implemented. |
Sounds great. I think it would be useful to have subtrees have some notion of "up". So if I mark the current level 3 heading (and child headings), I have an easy way to mark the parent level 2 heading. I'm not sure defun has that. sexp does but that sounds too small to be headings. If this required the expand-region package, that would be fine with me. Are you integrating blocks into the builtin paragraph commands? That seems right to me, but I haven't thought too much about the implications. |
The way I implemented it in my local branch, The main reason I thought about this is so that As to marking parent headings, For some examples, suppose we have the following subtree:
In the following examples,
If you want to test this out, see the feat/subtree-as-defun branch. The tests still need some work, so it's not fully ready to go, but it's usable. I suspect that the resulting marking/narrowing behavior will be preferred but that the navigation may be confusing. The good news is that the usual outline navigation keybindings ( Sorry for the extremely long reply, but as to your second question about blocks: currently I'm testing out separate bindings: Paragraphs currently are just whitespace- or list-marker-separated, but blocks are not broken by whitespace (e.g., a code block with a blank line will be treated as one block but two paragraphs). I think there's some utility in distinguishing the two, but the cost is extra keybindings... |
I just pushed some commits that include block movement, marking, and narrowing. Please let me know if you have thoughts. In the end, I decided to replace the paragraph-based commands rather than to add new bindings. Those keys are natural and except in special cases, I think a Markdown block is what you want. So now Regarding subtrees, I'm inclined to go forward with the defun = subtree approach unless there are concerns... Then to narrow to or mark the current subtree it would just be |
I have a file with headings at levels 1-4. The contents are - lists where each list item is one line.
|
Thanks for this useful feedback, as always!
|
Glad to help, thanks for listening. |
I have been having second thoughts about trying to force defuns (which
Today, I pushed several commits with related new features:
|
I like the page commands a lot. I like the subtree marking and narrowing commands. The plain text block movement commands do something I'll find very useful. One thing to consider, sublists. If I'm in a list with several top level items and each has several subitems (indented with a leading -), if I'm in a subitem, I think I'd like these block commands to move to the next top level item, currently they move to the end of the whole list. |
Great! I fully agree about list navigation. I also wish for list navigation commands at times, so it's on my list as well. I don't even think |
Move Markdown block movement and marking commands to C-M-{, C-M-}, and C-c M-h. In their place, add syntax-aware Markdown paragraph movement commands: M-{ (markdown-backward-paragraph), M-} (markdown-forward-paragraph), and M-h (markdown-mark-paragraph). The "plain text block" movement commands introduced in development since v2.2, which were not syntax-aware, have been removed. These paragraph and block commands differ primarily in granularity, with blocks being larger and containing multiple paragraphs. Take lists, for example: paragraph movement commands stop at each list item while block commands move over entire lists. This commit is related to GH-191.
Here's an update. The "plain text block" movement functions I added before were a bit of a kludge. I wasn't really happy with those, so in the latest update we now have distinct, syntax-aware "paragraph" and "block" movement functions, where paragraphs are more granular than blocks (i.e., blocks contain one or more paragraphs). The bindings are now as follows:
In terms of list items, paragraph movement moves item by item, regardless of level. Block movement moves across the entire list. I've also enabled outline movement commands (C-c C-p, C-c C-n, C-c C-f, C-c C-b, and C-c C-u) for list items, if you want to go to sibling or parent items in a hierarchical manner. When the point is in a list, these commands move by list items. Otherwise, they move by headings. Take blockquotes, for another example. Paragraph movement stops at individual paragraphs in a blockquote while the block movement commands move over the entire blockquote. There are still a few kinks in the list movement commands that I'm aware of, that will take some more in-depth work to fix, but I think this "big-picture" issue is closed now. Thanks again for suggesting this. |
Just a note that this seems to have broken shift-selection for CUA users. E.g. C-S-down previously selected the paragraph below (and does in other modes I have experience of), but now just moves the cursor. |
See GH-191. Thanks to Brendan Rocks for reporting this. <#191 (comment)>
Thanks, @brendan-r. I think this should be fixed now, but let me know if not. |
This is an enhancement idea. I have a long markdown file divided into sections with levels 2, 3 and 4; it's basically a list of restaurants by local areas. Today I wanted to look at a specific area and I wanted to narrow the buffer to that area. It was easy to use C-s to search for the level 2 section I wanted and the line below it was blank. With the cursor there I wanted some command like markdown-narrow-to-subtree or markdown-narrow-to-section.
I know about the (org-mode like) hiding (aka cycle visibility) that markdown mode can do. If there was some easy way to mark a section (or subtree) then I could use narrow-to-region, but I don't know of one. It would be great if the expand-region package could expand by enclosing section levels. It seems like now it goes from smallest enclosing section (e.g., level 4) to the whole buffer. mark-defun seems to mark the smallest enclosing section too. So I couldn't find some way to mark this whole level 2 section.
The text was updated successfully, but these errors were encountered: