In Emacs, what's the opposite of invisible text? - elisp

You can't see invisible text in the buffer, but if you save the file, it'll be there. I want the oppsoite -- something to display, but if I save the file it won't be written to disk.
In particular I want to display an ellipsis (the "..." symbol) where I have hidden text.
In case it's relevant, here's the code where I'd like to do that. The "fold" function hides text, and the "unfold" function shows it again. The region folded or unfolded is every line just below the current one with more leading space than the current one.

If you set the invisible property to a custom symbol my-fold:
(put-text-property startRegion endRegion 'invisible
(if toHide 'my-fold nil))
You can say that my-fold invisibility should use an ellipsis:
;; Cause use of ellipses for invisible text.
(add-to-invisibility-spec '(my-fold . t))
Further reading:
C-hig (elisp)Invisible Text
C-hig (elisp)Replacing Specs

Related

How can I bind a function key to emit a color code?

I'm making a terminal recording and I would like to change the terminal foreground color to emphasize certain parts (such as certain command line arguments) in the recording.
How can I map a function key to emit a color code in bash/readline?
I can bind to other things like the arrow keys using bind '"\e[21~":"\e[A"', so I think doing something like bind '"\e[21~":"\e[[31m"' should emit a color code and change the fg color.
It doesn't. How do I make this work?
If you bind a key to a string like \e[A then this key emits this string which in turn is again parsed by the readline library and interpreted (in this case to mean "up" which is then pointing to the function previous-history). The string is never printed to the terminal.
So if you want to print something, you need to bind a key to a function which prints something arbitrary (your ANSI color escape sequence). I'm not aware of such a readline function because it doesn't make much sense if you think it through. The problem is that readline has no notion (no internal model) of colored characters. Readline is for raw characters only, without character styles. Switching the color, entering some visible characters, then using cursor keys to edit already typed (maybe colored, maybe standard) characters -- stuff like this will lead to redraws of the complete line. In that process the colors will be eradicated quickly (because readline doesn't really know about them).
So I guess what you want just isn't possible. It is a feature not supported by readline and which you cannot simply add to it (correctly) from the outside without breaking things.

Sublime Text 3 unable to find text that is plainly there

Hitting cmd+f to find text in SublimeText, I frequently see something like:
Clearly 'someText' exists on the page. Why can't Sublime find it?
Note this sometimes seems to work, and sometimes fails. I can't work out the difference though.
How can I reliably find text with Sublime Text?
I've tried to reproduce this problem with Sublime Text 2 and this is what I found:
If you place caret before the text and the hit find, the text will be found
If you place the caret after the text and then hit find, the text will not be found
It seems that Sublime Text doesn't wrap search by default. You can enable it by toggling the button with the arrow icon (second one from the left of Find what, its tooltip should say Wrap). Then the search works regardless of the caret position.
Look at the buttons right before search box. Sometimes they are just get disabled accidentally, mis-click, or the short-cut get trigged, then the search doesn't behave as expected.
From left to right, RegExp, case sensitive, whole word, wrap(search whole doc, not just below current line), you can see them with mouse pointer hover.
I strongly suggest you to disable those shortcuts to prevent unexpected toggle of these :)
Also, turning off the regex may help you in searching for symbols which have special meaning in regex. For instance, someText(foo) will not be searchable in regex mode without escaping the brackets or putting the search string in quotes.

Disable wrapping for some lines but not others

I have a NSTextView subclass. It displays normal text (which should wrap, ideally around the 80-char line) and ascii style tables (which should not be wrapped).
Mockup:
As you see the text on top is wrapped, while the table extends.
I have code that figures out if a line is a table, but I need some ideas on how to go with the selective (non)wrapping.
Use multiple text containers with your layout manager.
"This one is the width of the text view (it wraps); the next one is as wide as it needs to be (doesn't wrap); etc."

Visual Studio 2010: While debugging, how can I copy string values containing carriage returns out of variables?

When I am stepping through code in c# (not sure if it's an issue in VB.NET) and looking at SQL stored in a string variable, sometimes I like to copy it and paste it into Notepad or my SQL program. If it contains carriage returns, though, it actually copies to my clipboard as line1\r\nline2. Is there a native method of copying this with actual carriage returns rather than carriage return escape codes?
Edit: This also applies to tabs which show as \t. This is happening because my code is reading SQL from a text file and the text file contains carriage returns and tabs. The alternative is to 1) not have any carriage returns or tabs in the SQL (which makes for ugly SQL) or 2) strip them out when reading the SQL into my string variable. I am not really keen to those options just for the sake of simplifying the debugging process, though.
It depends where you copy the value from.
If you hover your mouse over the variable when debugging, or look in the Locals window, you should see a little magnifying glass symbol in the tooltip.
Clicking this will open the Text Visualiser which should take account of any linebreaks.
For example, if my code is:
string test = "hello" + Environment.NewLine + "world";
Then I can look in Locals (notice it still shows \r\n there) or hover over test to see:
This opens the Text Visualiser from where you can copy/paste:
Put a breakpoint on the statment which has the variable (whole value you want to copy). As the control comes on the statement, move your mouse-pointer on the variable name. You will see a balloon box showing the variable name, a binocular icon and the value of the variable. Click on the binocular icon or the small down-arrow icon beside the binocular icon to view in it in text visualizer. Hope this is what you are looking at. This is in context with C# and hopefully its the same in VB.NET (but not sure).

term inside emacs:: how to turn "word wrap" off

In setting up my personal Linux command line development environment, I want to use term inside emacs b/c then I can switch to 'line mode' and copy/paste the output into any other buffer.
However, when I run mysql inside term inside emacs, the pretty sql tables still word wrap according to the width of that emacs window :(. I was hoping that emacs would truncate the bash output.
Is there a way to do this?
EDIT:
toggle-truncate-lines is on, so "word wrap" is off, but the problem is that before emacs even does anything with the text, the underlying bash process itself manually adds newlines to wrap text according to the width it's told it's using. That's at least how it acts. toggling truncate lines on/off doesn't change anything for me in the term buffer
I think what you probably want is "M-x toggle-truncate-lines". That toggles between wrapping or requiring you to scroll right and left to see the entire line.
You probably want to add something to the sql hook to turn off the wrapping:
(add-hook 'sql-interactive-mode-hook '(lambda () (toggle-truncate-lines 1))
I think Emacs might be setting the COLUMNS environment variable to indicate when the shell should wrap lines. Try setting it to a very large value and see if that helps.
I have no idea what other things this will break though.
Meta-X auto-fill-mode
This will toggle auto-fill mode and stop the line wrap.
The function term--unwrap-visible-long-lines is called by term-reset-size whenever the window is resized and appears to be responsible for the unwanted wrapping, and is not configurable. I hack this by advising the function to fix the wrapped width to a large value.
(defun my-prevent-term-unwrap (original-function height width)
(apply original-function (list height 10000)))
(advice-add 'term-reset-size :around 'my-prevent-term-unwrap)

Resources