show repeated selected text in emacs - emacs

I don't know which text editor have it but when you select text it show up where the same text appear in text with a box. It's usefull when you select variable and it show up where it's use in the code.
The text can show up with different backgorund when I copy the text and then call the function and dissapear when position of the cursor change.
Is it possible to do this in Emacs (probably is but how)?

Yes, Emacs has that (highlight matches of a given symbol or other pattern). Sounds like any of these correspond to what you are looking for:
Incremental search (aka isearch): C-s or C-M-s, then type what you want to match (or use C-w... to pick it up from the buffer).
Library highlight-symbol.
Library highlight, command hlt-highlight-symbol. (And see option `hlt-auto-faces-flag.) Does what library highlight-symbol does, and more.
Emacs 24.4 (i.e., current development snapshot), command hi-lock-face-symbol-at-point.
If you use library mouse3.el then right-clicking the mouse gives you the last two alternatives for the symbol under the mouse pointer.

You can maybe try to use cedet with ECB on Emacs.
You can install it with Meta+x list-packages or you can try another IDE like Kdevelop.

Related

How to write text inside a rectangle in emacs artist-mode?

I am learning artist-mode in emacs and finding it pretty interesting.
I want to create shapes and write text inside them as we can do with other software where one can draw shapes.
However, when I type some characters inside a rectangle, the shape gets distorted. The vertical line gets shifted by some characters.
Please see attached image.
Is there something I can do to fix it? Or is it a bug in artist-mode. I watched some screencasts and videos and did not remember anyone mentioning anything about this odd behavior.
I am on Mac and my emacs version is
GNU Emacs 25.1.1 (x86_64-apple-darwin16.0.0, NS appkit-1504.00 Version 10.12 (Build 16A323))
Try this before you type text into a rectangle.
C-x h (Select the whole buffer.)
M-x untabify <RET>
This will make you buffer tab free, which should solve the problem when you are typing.
Note that you should avoid using backspace for deleting text. Move your cursor and overwrite them instead.
There is a workaround I found for this cases.
select text mode
add the relevant text, RET
type term RET (here we specify the font)
RET (No ARGS for figlet, might also depend upon use-cases)
It may be a bit clumsy, but I usually do
select text mode
press Insert (Ovwrt)
add text
enter artist mode
I'm surprised not to see overwrite-mode. This replaces text at point rather than inserting it.
People have mentioned untabify to change tabs to spaces. Use whitespace-mode to see where those tabs (and spaces) are.

Change default EMACS mouse highlight behaviour

In EMACS the default seems to be to 'copy' any text highlighted with the mouse. I'm attempting to replicate the functionality of modern text editors, where I can highlight a section of text and press 'paste' to replace it. I have so far added
(delete-selection-mode 1)
to my init.el
The problem is, if I copy something, then highlight to paste in its place, I end up pasting what I had just highlighted, changing nothing.
What do I need to change to fix that behaviour?
The most powerful element of emacs is its introspection features, lets have a look at how we can use them to try and solve this problem. We must use the power of the source.
One of the most important tools for introspection in emacs is the describe-key command which is bound to C-h k. It brings up the documentation of whatever keystroke is called after it. So in our case if we press C-h k and then click and drag we will see the documentation for <down-mouse-1> and more importantly for <drag-mouse-1>. The documentation states that "<drag-mouse-1> at that spot runs the command mouse-set-region". Below it then gives some documentation for this command. It says
Set the region to the text dragged over, and copy to kill ring.
This should be bound to a mouse drag event.
See the ‘mouse-drag-copy-region’ variable to control whether this
command alters the kill ring or not.
Now we know that somehow mouse-drag-copy-region controls whether or not the highlighted text is copied.
If we follow the link of that variable it tells us the default value and some documentation:
If non-nil, copy to kill-ring upon mouse adjustments of the region.
Now all we have to do is set the variable to be nil to get the effect that you want. Place the following code at the end of your init file and you should be all set
(setq mouse-drag-copy-region nil)
I hope that this helps you with this problem and that more importantly it helps you with further issues.
By default, selecting a region with the mouse does not copy the text to the kill ring. If your Emacs does this, you probably have set the variable mouse-drag-copy-region.
In a fresh Emacs (24.5 started using -Q), you can do the following:
Start delete-selection-mode.
Mark a region using the mouse. Copy it using M-w.
Mark a second region. Replace it with the first using C-y.
I see two alternatives, neither of which does exactly what you request. (For both, yes, turn on delete-selection-mode.)
Use the secondary selection for the text to copy, and use the primary selection (the region) for the text to be replaced.
You copy text into the secondary selection using the Meta key plus the mouse - for example, press and hold Meta (the Alt key, usually) while dragging or double-clicking mouse-1.
You paste the secondary selection using Meta plus mouse-2.
Select text with the mouse, then copy it to the kill-ring using M-w. Then select the text to replace with the mouse and use C-y to paste the copied text to replace it.

Emacs - How to keep text formatted to other editors?

I'm a beginner with emacs. Altough I'm finding it amusing and challenging, I still don't know some basic things, like, when I open a text or a piece of script wrote in another editors, emacs don't show the text formatted properly (missing all tabs, all text left-aligned) and vice-versa.
Also, when I copy a link with emacs with M-w, my clipboard is still empty and I can't paste it in a browser. I already did my "homework". I've read the tutorial and I'm almost finishing the manual and didn't see anything to address that.
tnx in advance.
Some editors, like Intellij IDEA for example, will indent code based on how they understand it and not based on how it was actually indented, there's no Emacs mode that operates in the same way, not to my best knowledge. If you were using something like Eclipse or MS Visual Studio before - then you probably just have a different size of tab character (this is why some programmers insist on indenting code with spaces rather than tabs). But the width of the tab character is adjustable. In order to customize it you would:
add in your initialization file (usually .emacs file in your $HOME directory, you can create one, if it is not there yet):
;; makes tab character as wide as four space characters
(setq default-tab-width 4)
though some other major editing modes override this variable, you would need to tell what language you are dealing with to get better instructions.
Clipboard, see this answer: How to copy text from Emacs to another application on Linux if you are on Linux, then likely you need to set x-select-enable-clipboard to t.
Aligning text to the right (or left for LTR languages) is not possible in Emacs, as far as I understand. You could align block of text, if you split it into lines and align on the line ends, but that would mean aligning by adding spaces at the beginning - something you don't really want to do.
Tabs should work (you might need to fix the width). Use mouse to select to the clipboard, or use CtrlInsert to copy and ShiftDelete to cut.
Assuming emacs has picked the right mode for the file - it usually does - you can press C-x h to select all, then TAB to indent all selected lines. What other editors are you using, and what platform(s)?
As for the clipboard issue, some builds of emacs work correctly with the native clipboard, some don't. You might want to investigate CUA mode.

Code folding for LaTeX in Emacs

Is there an Emacs minor-mode (or piece of elisp code) that lets you selectively hide/show environments while in LaTeX mode? For instance, I would like to move to the beginning of a long \begin{figure} block, hit a keystroke, and have the contents of that figure environment hidden from view. Similarly with \begin{proof} and so on, and ideally even with \subsections.
Is this possible? I just tried hs-minor-mode, allout-mode, and outline-minor-mode, but most of them don't recognize LaTeX's environments, e.g. hs-minor-mode fails with "scan error: unbalanced parentheses". I would prefer not to have to enter explicit folding marks like {{{ as in folding-mode.
[Ideally it would be great if the folding were persistent, but I see that that question doesn't have an accepted answer yet.]
AUCTeX does folding: http://www.gnu.org/software/auctex/manual/auctex.html#Folding
A popular complaint about markup languages like TeX and LaTeX is that there is too much clutter in the source text and that one cannot focus well on the content. There are macros where you are only interested in the content they are enclosing, like font specifiers where the content might already be fontified in a special way by font locking. Or macros the content of which you only want to see when actually editing it, like footnotes or citations. Similarly you might find certain environments or comments distracting when trying to concentrate on the body of your document.
With AUCTeX’s folding functionality you can collapse those items and replace them by a fixed string, the content of one of their arguments, or a mixture of both. If you want to make the original text visible again in order to view or edit it, move point sideways onto the placeholder (also called display string) or left-click with the mouse pointer on it. (The latter is currently only supported on Emacs.) The macro or environment will unfold automatically, stay open as long as point is inside of it and collapse again once you move point out of it. (Note that folding of environments currently does not work in every AUCTeX mode.)
In order to use this feature, you have to activate TeX-fold-mode which will activate the auto-reveal feature and the necessary commands to hide and show macros and environments. You can activate the mode in a certain buffer by typing the command M-x TeX-fold-mode RET or using the keyboard shortcut C-c C-o C-f. If you want to use it every time you edit a LaTeX document, add it to a hook:
(add-hook 'LaTeX-mode-hook (lambda ()
(TeX-fold-mode 1)))
If it should be activated in all AUCTeX modes, use TeX-mode-hook instead of LaTeX-mode-hook.
Once the mode is active there are several commands available to hide and show macros, environments and comments...

Defining new tooltips in Emacs

I would like to add custom tooltips to emacs.
More specifically, whenever I hover on a symbol (function/variable) name
with my mouse of I would like to see a tooltip with the symbol's definition.
I know that I can find this kind of info with a tool like cscope but I have no idea how
to attach the output of cscope to a tooltip.
does anyone have a partial (how to link a callback to a tooltip in emacs in general) or
a full (how do I actually link the output of cscope to a tooltip) solution to this?
Thanks,
Nir
Your Emacs installation should include the Elisp reference manual (if not, download it now - you're going to need it when developing your mode). To access it, go to Info (C-h i) and look for a node labeled "Elisp", sometimes in a separate "Emacs" menu. Type i for index and tooltip to look for information on tooltips. You should find node 32.19.4 Properties with Special Meanings, which tells you that the content of the help-echo property is a string that is the tooltip content, or a function that can construct the tooltip dynamically. Explore the manual around that node to find out more about text properties and how to set them.
Here's a simple example:
(insert (propertize "foo\n" 'help-echo "Tooltip!"))
Type this into your *scratch* buffer and press C-j to run the code. Then point your mouse at the word "foo" and you should see the tooltip.
There is an AutoOverlay package that can automatically add overlays, and tooltips associated with those overlays, based on a regex match of the buffer text.