TextExpander Whitespace Issue When Programming - coding-style

I am an avid TextExpander for Mac user. I use it to expand code across multiple text editors. I have had one issue that I wanted to run by fellow programmers who use TextExpander for possible solutions.
When I am expanding multiple lines of code on a line that has leading whitespace, TextExpander resets the leading whitespace on all lines beyond the first one.
Example:
If I am trying to expand a debug snippet I use all the time, from an indented line, it appears like so.
echo '<pre>';
print_r();
echo '</pre>';
The first line is indented because that is where I typed the expand abbreviation. Is it possible to maintain the leading whitespace status across all lines?
echo '<pre>';
print_r();
echo '</pre>';

I'm afraid TextExpander can't mimic the auto-indent behavior of your code editor.
If you always enter these at the same indent level, please note that you can use option-Tab to insert a tab when editing a snippet in TextExpander's snippet editor.
If your code editor respects the indent level of formatted text, you could instead change the snippet type from Plain Text to Formatted Text, Pictures using the popup above the snippet editor then choose Format -> Text -> Show Ruler to show the text view ruler, which works the same as in TextEdit and other apps.
If you'd like further assistance, write us at: support#smilesoftware.com

Related

Im using vim to check man page, and there is some weird character,how to make it normal?

I'm trying using
man ascii | vi -
to check ascii manual with vim,
then there are some weird character like '^H'
weird character in vim
how to make it normal?
EDIT:
i think this is due to some wrong config of my vim, or terminal,
because i tried some other machine,and it works fine,any body help?
What you're seeing here is the man page convention for typesetting bold and underlined characters.
The ^H character is the "backspace" or BS character, which you can find in ascii(7) as ASCII 8.
Displaying as ^H is a convention to indicate "Control-H", the caret being a symbol for the "Control" key, since that's a key combination that generate this control character (note that "H" is the eighth letter, also it's on the same row as BS in the ASCII chart at the man page.)
Also note that ^H here is a single character and not the separate ^ and H characters. If you move along that line with l motion repeatedly, you'll see Vim skips the Hs. Vim might also display them in a different color to make it clear they're special characters.
The effect you're seeing here is called overstruck characters and it comes from the days when computers would be connected to line printers rather than screens. Man pages were created early in the Unix days and are typeset with a program named nroff (which has roots that predate even Unix) that uses these sequences to encode its text decorations, even to this day.
So one way to make text bold (or, print it stronger) was to print a letter, back out one space, then print it again. In your example, N^HNA^HAM^HME^HE is being used to print the word NAME in bold.
Typically, you'll use a man pager program that knows how to handle those sequences. For instance, less has specific support for overstruck text and is able to recognize those sequences using backspace (or carriage return, also possible to use it for that) and convert into bold or underline text using terminal escape sequences which actually achieve those effects in a terminal.
If you're using a different pager, often you'll use col -b to strip your text from those sequences. (See col(1) for details.) Note that col -b doesn't produce terminal escape sequences around overstruck text, it simply removes all overstriking, leaves the text plain, so any text reader can display it.
(In that sense, man ascii | col -b | vi - is one possible way around your issue, but not the best one.)
Vim doesn't support overstruck text or terminal escape sequences in text it receives as input. So the approach used to use Vim as a man pager is to strip all overstriking (same as col -b does) and then use Vim's syntax highlighting feature to mark man page sections etc. (So instead of seeing the original markings typeset into the man pages, those are all being stripped and you're actually seeing Vim syntax configuration for man pages.)
This is accomplished by the manpager.vim script, which is shipped by default with Vim and which registers a :MANPAGER command that you can access as vim +MANPAGER -.
You'll see that part of what that does is to remove overstriking, same as col -b does. It also sets the file type correctly and enables syntax highlighting, setting up Vim as a suitable viewer for man pages.
I think this is due to some wrong config of my vim, or terminal, because I tried it in some other machine and it works fine there.
I'd say this is most likely due to the man pages being typeset differently between the two systems.
Man pages themselves and the pipelines used to generate them from the source code are not very uniform and you'll find differences across operating systems or even Linux distributions.
It's possible that on your other system all man pages get stripped using col -b at creation time, or that man will strip them when piping them to something that's not what's set in $MANPAGER, or even that they don't have anything marked as bold or underline in their sources.
Hard to tell exactly which (your reference to working fine on another machine lacks details to tell), but this would be my bet.
In short: To use Vim as a pager for man pages, instead of piping them to Vim, set it up so that man will run vim as a pager itself.
In Vim, see :help manpager.vim which has instructions on how to set this up.
In short, all you need is to add this line to your ~/.bash_profile:
export MANPAGER="vim -M +MANPAGER -"
After setting that up and logging in again, all you need is:
$ man ascii
And man will launch vim in the right mode for you.

Notepad++ convert leading spaces to tabs upon entry

Very close to reverse of this question. I prefer coding with 2-whitespace indentation, but need to have files indented with tabs to align with project convention. What I would like to do is preferably automatically convert 2 spaces upon entry to tab symbol in Notepad++ and have the editor configured to tab length of 2.
A possible manual way for doing this could be Edit->Blank Operations->Space to TAB but this converts all of my spaces to tabs, even those of length 1 - which are, for example, spaces between function arguments, not just leading spaces.
In a perfect case scenario I'm trying to achieve formatting style as described in this question, but with typing just spaces and the editor taking care of the rest.
I'm on Notepad++ 6.0, but willing to upgrade if this helps
Let me complete the answer of Ari Okkonen to add a workaround to the problem commented by Sergii Zaskaleta of mixed tabs and spaces at the beginning of the line.
Settings->Preferences->Tab Settings->Tab size: 2 (if not already)
Edit->Blank Operations->Space to TAB (Leading)
Select a block of lines of text with the problem of mixed spaces and tabs. Press [Tab] and [Shift]+[Tab] to add and remove a tab from each line. In the process, the leading spaces had been converted to tabs.
A manual way that seems to work: After having edited the file before saving you may try (Works in Notepad++ v6.8.3):
Settings->Preferences->Tab Settings->Tab size: 2 (if not already)
Edit->Blank Operations->Space to TAB (Leading)

How to change multiple entries in config files

I notice in VS2013 that if I highlight text with a view to making a change, the same text is highlighted elsewhere in the file. However, I can't seem to find the option to reflect the change in multiple places when I start typing.
Is this feature just for information only or can I actually do multiple replacements by typing the change once?
This is not supported out of the box.
But there is a nice plugin you can use to enable this, called MultiEditing.
H/T to Scott Hanselman :)
Also note that even in standard VS2013, you can edit multiple lines by "box-highlighting".
This is where you create a "box-selection" either by holding down Alt and dragging a box around the text, or by Alt+Shift+ArrowKeys. Then start typing and the same text will appear on multiple lines.
e.g. with the following text:
Some text to demonstrate
Some info to demonstrate
Some more to demonstrate
...if you Alt+drag a box-selection around all 3 occurrences of the word to, and then type which, it will look like this:
Some text which demonstrate
Some info which demonstrate
Some more which demonstrate
This also works with copy/paste - the pasted text gets applied to all lines within the box-selection.
It's pretty hard for me to describe here, so try it yourself!

How to create code box without rich text formatting

My question is related to this topic How to copy and paste code without rich text formatting? except its from the opposite viewpoint: I'm creating a document from PowerPoint in which I have code snippets in text boxes. I want to make the document as simple as possible by making the code snippet text boxes easy to copy and paste the code into a terminal to run without editing anything. However, the way I have it right now is that when I copy and paste it keeps the formatting and I have to go though letter by letter to erase the end of line symbols. How should I format this in PowerPoint?
You can get rid of most formatting by copy/pasting from PPT to Notepad and then copy/pasting from there to your terminal program, or if the latter has a Paste Special command, you should be able to paste as plain text, which'd get rid of formatting.
Line/Paragraph breaks are another matter. If the end of line symbols are the only formatting problem when you've pasted the text into a terminal (emulator program, I assume), it sounds as though the terminal's using CR or LF as a line ending, whereas PPT's using CR/LF pairs. It might only be necessary to reconfigure the terminal software to use CR/LF.
It's worth a look at this page on my site, where I explain what line and paragraph ending characters are used by different versions of PowerPoint in different situations.
Paragraph endings and line breaks
http://www.pptfaq.com/FAQ00992_Paragraph_endings_and_line_breaks.htm
Sorry, my mistake was not realizing that PowerPoint auto formats hyphens and quotation marks to make them stylized, and the terminal was not recognizing the symbols. All I did was type in a quotation mark/hyphen then copying that before I pressed the space bar after it to save the original formatting.

Capture user input by opening a text editor with content

From a bash script, I'd like to
Open the default text editor for current user
Paste a string $original_content in it
Once the user modifies the content then closes the text editor,
Capture the modified string into a variable $modified_content
Then save $modified_content to an $output_file
Google searches for capturing user input shows read which is not what I'm looking for.
Can someone point me to the right direction?
Thank you
This method should hopefully work for most editors:
#!/bin/bash
original_content="Your original content"
echo $original_content > /tmp/user_input.tmp
# For example:
# DEFAULT_EDITOR=/usr/bin/vi
$DEFAULT_EDITOR /tmp/user_input.tmp
modified_content=`cat /tmp/user_input.tmp`
echo $modified_content > /tmp/output_file
This script may be a little drawn out but it performs all the actions you wanted except for the pasting part, since you'd probably have to accommodate for all varieties of editors to properly "paste" a string. This script utilizes the benefit that calling most editors with a filename as a parameter opens that file for editing thereby "pasting" your $original_content in the editor.

Resources