Bold marked region in org mode - emacs

Is there a way in org-mode to mark region (one or few words) and make them bold/italic?
Currently, if I want to turn bar into bold face, I have to move the point before the b add * and then navigate the point right after r and add another *. I want to be able to mark the whole word bar, hit something like C-c C-f C-b (did someone said AUCTeX?) and obtain *bar*.

org-emphasize does what you need. It is bound to C-c C-x C-f and then you suppy either the marker (* or _) or the first letter of the corresponding HTML tag (e.g. e for <em>).
Documentation here: http://orgmode.org/worg/doc.html#org-emphasize

Related

How to get Contex reveal work in org mode

Having a hard time figuring out what C-c C-r does context reveal
Manual says "With a prefix argument show, on each level, all sibling headings. With a double prefix argument, also show the entire subtree of the parent."
When all the Headings are collapsed and I do C-c C-r on a Heading 1
nothing happens
If I try it on a Heading2 or Heading3 when it is collapsed
nothing happens
If I try C-u 2 C-c C-r on a second level heading
Do I get to see all Heading 2 siblings with the current heading fully expanded ?
How can I make this work ?
Or does this work only in agenda views or sparse trees only ?
Got it. its for sparse trees.
After C-c / when the cursor is on the the highlighted entry, C-c C-r works. :)

Running a macro till the end of text file in Emacs

I have a text file with some sample content as shown here:
Sno = 1p
Sno = 2p
Sno = 3p
What i want is to remove the p from each of the columns.
With this intention i write a macro:
M-x //go to buffer
C-x (//start the macro
C-s = // search for equalto sign
RET C-f C-f // reach to te alphabet 'p'
DEL // Delete
C-n C-x )//go to new line and Close the macro definition
C-x e
Pressing e twice will remove p, but in case i want to do the same stuff till the end of file, how can i do it i can't keep pressing e if i have 20000 such lines. What should be done??
Please donot suggest regex, as this is a sample example, not the actual case.
Please donot suggest any elisp, i am comfortable with remembering shortcutf for emacs.
M-0 C-x e to repeat last macro until an error happens (after the final line, either C-s = or C-n will be an error).
You may hear an annoying beep.
You can use the "apply-macro-to-region-lines" function to apply the last defined keyboard macro to all lines in a region. So, the steps you follow are:
Define your keyboard macro (which you had already done but I've added another C-f to the 3rd line):
C-x (
C-s =
RET C-f C-f C-f
DEL
C-n C-x )
Select the whole buffer with the "mark-whole-buffer" command (by default, it's bound to C-x h). Alternatively, if you just want to change a certain number of lines, just select the lines you want changed.
Run the "apply-macro-to-region-lines" function (by default, it's bound to C-x C-k r).
All the p's will be removed.
I usually give a name to the macro after defining it with M-x name-last-kbd-macro, so I can call it with M-x conveniently. And then I call it with a numeric prefix. E.g.
M-1000 M-x macroname
The files I work on usually don't have 1000 places where the macro can act, so 1000 is large enough and it will stop automatically at the end of the file. You can use, say, 1000000 as a prefix if you have larger files, and if it's still not enough then you can call it again with 1000000 as prefix.
you may try: M-20000 C-x e so as to do the stuff for 20000 times, after you define the macro.

Save the shape of a rectangular selection in an Emacs register

I need to repeatedly copy text from a fixed size rectangular region and I'd like to be able to save the shape of that rectangular region in a register so I don't have to keep re-creating the same size.
cua-set-rectangle-mark (<C-return>)
Move point to create a region 8x16 (note: this is the step I want to remove)
piture-clear-rectangle (C-c C-k)
Move point to new location.
picture-yank-rectangle (C-c C-y)
I'd like to replace steps 1 and 2 with a single 'paste rectangular region from register' command. Is this possible?
Wouldn't it be easier to simply use a keyboard macro for this?
E.g.:-
C-x C-( [start recording kbd macro]
steps 1-2
C-x C-) [end recording kbd macro]
Then
C-x e [execute kbd macro]
You probably want to use copy-rectangle-to-register and insert-register:
C-x r r runs the command copy-rectangle-to-register, which is an
interactive compiled Lisp function in `register.el'.
It is bound to C-x r r.
(copy-rectangle-to-register REGISTER START END &optional DELETE-FLAG)
Copy rectangular region into register REGISTER.
With prefix arg, delete as well.
To insert this register in the buffer, use C-x r g.
Called from a program, takes four args: REGISTER, START, END and DELETE-FLAG.
START and END are buffer positions giving two corners of rectangle.
insert-register:
C-x r g runs the command insert-register, which is an interactive
compiled Lisp function in `register.el'.
It is bound to C-x r g, C-x r i.
(insert-register REGISTER &optional ARG)
Insert contents of register REGISTER. (REGISTER is a character.)
Normally puts point before and mark after the inserted text.
If optional second arg is non-nil, puts mark before and point after.
Interactively, second arg is non-nil if prefix arg is supplied.
See also:
C-xrc: clear-rectangle
C-xrd: delete-rectangle
C-xrk: kill-rectangle
C-xro: open-rectangle
C-xrr: copy-rectangle-to-register
C-xrt: string-rectangle
C-xry: yank-rectangle
EDIT:
Right, I completely misunderstood the question.
If you still particularly want to use registers, you could save and re-execute point movements with something like this:
(set-register ?a [right right right down down])
(command-execute (get-register ?a))

In Emacs, how to go back to previous line position after using semantic Jump to Symbol?

I know how to go to a variable definition in Emacs using semantic-mode. It works well in a single file (I think it doesn't work if the definition is in another file). Using C-c , j, I can go to the definition of the variable, but, how do I jump back to the previous line? Currently I use display Symref C-c , g, and select the displayed symref.
Is there any straight method?
Use:
C-u C-space or C-u C-#
If you want to navigate back between buffers, you can use:
C-x C-space or C-x C-#
This makes Emacs jump to the mark (and set the mark from position popped off the local mark ring) which has usually been set by a previous jump command.

How to highlight all occurrences of a word in an Emacs buffer?

Notepad++ has a convenient feature: if you select a word in your text (not necessarily a keyword), the word is highlighted throughout the text. Can this be done in Emacs as well? And if so, how?
It doesn't necessarily have to work exactly like Notepad++ (i.e., via selection); ideally, I would like to set up a key binding that causes all occurrences of the word under cursor to be highlighted.
It would be great if the highlights were permanent, i.e., moving point away from a highlighted word should not cause the highlight to be removed.
Also, it would be useful if there was a solution that made it possible to navigate between highlights (using custom key bindings).
The hi-lock suggestions are good. I think it's easier to use the M-x versions, though:
M-x highlight-regexp RET <REGEXP>
M-x highlight-phrase RET <REGEXP>
highlight-phrase is just a bit of sugar around highlight-regexp that ignores case and translates a space in the regex to match arbitrary whitespace. Handy.
Maybe highlight-symbol.el at http://nschum.de/src/emacs/highlight-symbol/ is what you are looking for:
Type C-s, then type the current word or type C-w. As a bonus, you can now hit C-s again to search for the word.
This is called incremental search.
What I use is idle-highlight
http://www.emacswiki.org/emacs/IdleHighlight
M-x idle-highlight sets an idle timer that highlights all occurences in the buffer of the word under the point.
To enable it for all programming modes, in ~/.emacs.d/init.el:
;; highlight words
(add-hook 'prog-mode-hook (lambda () (idle-highlight-mode t)))
Light-symbol will highlight whatever symbol point is over.
Alternately, you can use occur, which lists all lines matching a regexp. It's useful to quickly see all functions in a class.
Nobody mentioned symbol-overlay mode. It's basically a better rewrite of highlight-symbol-mode. "Better" as in, lacks bugs of original highlight-symbol (such as, temporary highlight getting stuck, or the temporary highlight disappearing for moving inside the highlighted word; or not being able to highlight symbols like *), better integrated, and maintained. See "Advantages" paragraph of its README.
You can install it as usual, with M-xpackage-install (make sure to update package list beforehand with package-list-packages). For reference, at the bottom I attached code I use to enable the mode and disable a few of the more advanced features which you may or may not want.
Notepad++ has a convenient feature: if you select a word in your text (not necessarily a keyword), the word is highlighted throughout the text. Can this be done in Emacs as well? And if so, how?
Once you enable overlay-symbol, occurrences on the screen will be shown for every word that you put cursor upon after a timeout (timeout by default is 0.5s, can be configured with symbol-overlay-idle-time variable). If a word don't get highlighted, this means there's just one match on the screen (the one you put cursor upon), hence there's no need to highlight it.
It would be great if the highlights were permanent, i.e., moving point away from a highlighted word should not cause the highlight to be removed.
To highlight the word under cursor permanently there's a function symbol-overlay-put. To unhighlight call it once again.
In my config example it's bound to Logo+` key.
(require 'symbol-overlay)
(defun enable-symbol-overlay-mode ()
(unless (or (minibufferp)
(derived-mode-p 'magit-mode)
(derived-mode-p 'xref--xref-buffer-mode))
(symbol-overlay-mode t)))
(define-global-minor-mode global-symbol-overlay-mode ;; name of the new global mode
symbol-overlay-mode ;; name of the minor mode
enable-symbol-overlay-mode)
(global-symbol-overlay-mode) ;; enable it
(global-set-key (kbd "s-`") 'symbol-overlay-put)
(setq symbol-overlay-ignore-functions nil) ;; don't ignore keywords in various languages
(setq symbol-overlay-map (make-sparse-keymap)) ;; disable special cmds on overlays
This may not be as nice as what you were hoping but if you put
(global-hi-lock-mode 1)
in your .emacs file then you can type C-x w h REGEX <RET> <RET> to highlight all occurances of REGEX, and C-x w r REGEX <RET> to unhighlight them again. Again, not as elegant as you'd probably like, but it'll work.
Try http://www.emacswiki.org/emacs/msearch.el
All occurences of the text selected with the cursor are highlighted.
You have to drag over the string which you want to highlight. That enables you to easily change the selection without changing the highlight.
If you want to preserve the highlighting of a string you can freeze it.
You can enslave a buffer to another buffer. Text selected in the master buffer will also be highlighted in the slave buffer. That is useful for comparing buffers.
It is also useful for taking notes in one buffer while you investigate the text in another one. You can have a collection of keywords in the notes buffer. Drag over such a keyword and its occurences in the investigated text will be highlighted.
I am using this stuff for years now. I added the freezing quite recently. So, maybe something is broken. If this is the case leave me a note on http://www.emacswiki.org/emacs/msearch or here.
Check Interactive Highlighting
Should be:
C-x w h word <RET> <RET>
Try iedit. It highlights the word at point and lets you edit all occurrences of it easily. With an additional keystroke (C-'), it hides all the lines without that word in it. Very handy!
Commands in library highlight.el
let you (un)highlight text matching a regexp (in this case a symbol), using overlays or text properties. You can cycle among the occurrences. Highlighting can be temporary or persistent. (more info).
This maybe won't highlight but will search for a word without you needing to type it...
when you've reached the word you wanted to search, C-S, then read the full word with C-W then you can C-S and it will search for it. In my Emacs it also highlights all instances in the document.
This package available in Melpa works, you can customize the highlight style as well.
https://github.com/ignacy/idle-highlight-in-visible-buffers-mode