I make my notes in this order:
* FIRST
* SECOND
* THIRD
...
* LAST
what I want when I export to html or latex is the reverse order:
* LAST
...
* FIRST
so
is there any way or command to reverse the order in org file directly ?
is there any way to reverse the order while I export the org file to html/latex ?
either should be fine I think.
I don't think there is a predefined command you are looking for. You can implement it by yourself.
If it's a one-time task I would use emacs macro:
You show only top-level headlines. Then you go to the first headline and start macro C-x ( .
You select the line C-SPACE C-n and you type C-u M-x prepend-to-register . C-u deletes the line as well. You stop the macro C-x ) .
Now you repeat the macro for all top-level headlines M-0 C-x e .
And you insert the register C-x r i .
An alternative for evil users:
Fold all headlines (S-TAB) and go to the last one (G)
qq Record macro to register q
"Pddk Append current headline to register p and go a line up
q Save macro
#q and then X## with X being the number of remaining headlines
"pp Paste from register p
Related
I used to start all my comments from column 60.
Is there a trick in Emacs with which for the current line, anything after (and including) // is pushed to column 60?
Example
cmp A, B // comparing against a reference
becomes
cmp A, B <-- extra spaces added until column 60 ---> // comparing against a reference
Set comment-column to 60, and hit M-;.
Note that M-; runs comment-dwim which tries to do what you mean. Notably, if the region is active, it will comment out the entire region. If this gets in your way, the command that does what you ask for above is comment-indent, which you could bind to a suitable key.
Set the comment-column as said by legoscia, select a region and call M-x align-regexp RET // RET. That will align your comments on the same column.
For the doc: C-h f align-regexp.
There's two variations. I think you can select a rectangle and add stuff to the beginning and end of all lines.
I'd also like to know if it's possible to select multiple points that are on different offsets to where you edit all the points at once. I think Yasnippet provides something similar, but only when you use a predefined template. Something like this.
<div class="">
<a class="">
where i can mark a point on both class things and typing will edit both class attributes. Is it possible?
Emacs Rocks! describes mark-multiple, which does what you want. (Here's their video introduction.)
EDIT: #Lifton points out it has been superceded by multiple-cursors.
In addition to Juancho's answer, I've used Steve Yegge's multi-select for your purpose. Example usage (the first example will provide what I think you want):
C-u C-M-m w foo <RET> <RET>
- inserts/prepends "foo" to every multi-selection (you can also append or replace text)
C-u -1 C-M-m r <pre>\(\w+\).+\s-+\(.+\)</pre>
- selects first and last word of the contents every <pre> tag
(provided the contents don't span multiple lines)
C-M-m x M-x upcase-region
- converts all multi-selections in buffer to uppercase
C-u M-w C-q C-j --- C-q C-j <RET>
- saves all multi-selections to kill-ring as a single item,
with selections separated by "---" on a line by itself
I have 2 columns, separated by comma. How can I swap those columns with Emacs?
I have the following:
column 1,column2
x1,x2
y1,y2
f1,f2
and I want it like this:
column2,column 1
x2,x1
y2,y1
f2,f1
Use M-x query-replace-regexp and then:
\(.+\),\(.+\)
as replace regexp and
\2,\1
for replacement.
In Emacs, you need to escape grouping parentheses with \. So, above regexp would be usually written as
(.+),(.+)
which means that you want everything before comma in first group and everything after comma in second group.
\2,\1
means: write second group, then comma, then first group.
While you can apply techniques given by other people, you can also use the org-mode tables.
Once you convert the data into org-mode table, it is very easy to swap the columns by simple keystrokes. You can have M-x org-mode, select the region then do M-x org-table-convert-region, and then M- on the right most column. I am not sure, how to export the data as CSV, but that should be very easy for you with replace-regexp. This can be helpful: http://www.gnu.org/software/emacs/manual/html_node/org/Tables.html#Tables
Similar to the answer given by #darioo, type the following into the top of your buffer:
(query-replace-regexp "\\(.*?\\),\\(.*\\)" "\\2,\\1")
Then, put your cursor at the end of this line and press ctrl-x, ctrl-e.
You will have an interactive search-and-replace for which you press the space bar to make the change, and press ctrl-g to quit. If you press ! (exclamation mark) then the search will cease being interactive and take place on all matching text.
If you want to reverse the changes then press M-x (usually ESC followed by x) and type undo and press enter.
Emacs has a rectangular selection mode, see for example: http://emacs-fu.blogspot.com/2008/12/working-with-rectangular-selections.html
Even better, if you enable cua-mode, entering Ctrl-Enter will put you in rectangle selection mode that is very easy to use.
http://trey-jackson.blogspot.com/2008/10/emacs-tip-26-cua-mode-specifically.html
Use a macro !
Go to the first line of the buffer
Start recording a macro (F3)
Move to the beginning of the line (^a)
Search for comma (^s ,)
Transpose (M-t)
Move cursor down one line
Stop recording macro (F4)
Select the rest of the lines and:
M-x apply-macro-to-region-lines
UPDATE: This doesn't work properly if you have multiple words in a column. Looking for a more general solution...
I'd like to be able to set multiple marks in Emacs like Vim does. In Vim you might press m b and that would set a mark at that line in the file. Later pressing ' b will move your cursor back to that line. You can make multiple marks with m{a-zA-Z}. Is there a way to have multiple marks like this in Emacs?
From Emacs documentation :
C-x r SPC r
Record the position of point and the current buffer in register r (point-to-register).
C-x r j r
Jump to the position and buffer saved in register r (jump-to-register).
But if you want your positions to persist automatically from one Emacs session to the next, you should use Bookmarks :
C-x r m RET
Set the bookmark for the visited file, at point.
C-x r m bookmark RET
Set the bookmark named bookmark at point (bookmark-set).
C-x r b bookmark RET
Jump to the bookmark named bookmark (bookmark-jump).
C-x r l
List all bookmarks (list-bookmarks).
M-x bookmark-save
Save all the current bookmark values in the default bookmark file.
You can use what Emacs calls registers. The documentation explains them better than I can.
Try the mark ring for quick marks:
C-spaceMake a mark at current position; also, add position to mark ring.
C-xC-xJump back to previous mark.
C-UC-spaceCycle through marks in the mark ring.
I used Vim for a decade before switching to Emacs a few years ago, and while the registers and bookmarks looked good at first, the mark ring is what I actually end up using 90% of the time. Usually I just use the C-space, C-x C-x, but cycling works, too.
Btw, realize that doing large non-arrow key movements like M-v will often add a mark to the mark ring. Just practice these key combos and you'll likely find them sufficient for most tasks.
Radix already did a good job explaining the registers and bookmarks, and those are useful for locations in files that will be referred to often or need annotation.
Vanilla Emacs makes you specify a name for each bookmark. What you want, it sounds like, is a quick way to create bookmarks without naming them -- just hit a key. You want autonamed bookmarks, available with Bookmark+. You can even have them be automatically highlighted, if you like (the fringe or the line).
Have a look at this: http://www.cs.utah.edu/dept/old/texinfo/emacs18/emacs_13.html
When using bookmarks to open a file, is there a way to always open at a particular position of the file?
Emacs default behavior when bookmarking with C-x r m is to bookmark the file AND the position. So, if you use that command (bookmark-set) it will have the behavior you're asking for.
If you C-h k C-x r m to view the documentation:
C-x r m runs the command bookmark-set,
which is an interactive compiled Lisp
function in `bookmark.el'.
It is bound to C-x r m,
.
(bookmark-set &optional NAME
NO-OVERWRITE)
Set a bookmark named NAME at the
current location.
It can even set two positions (the region), if you use Bookmark+.