How can I make Emacs automatically wrap lines of text that I've already written such that no line is longer than, say, 70 characters. In other words, I'd like to do "auto-fill-mode" after-the-fact.
Is this possible?
Look at fill-paragraph and fill-region. If I remember correctly, it's bound to M-q by default. To set the line width, use C-xf.
In addition to fill-paragraph and fill-region, take a look at these commands:
file-individual-paragraphs: "Fill paragraphs of uniform indentation within the region.
This command divides the region into "paragraphs",
treating every change in indentation level or prefix as a paragraph boundary,
then fills each paragraph using its indentation level as the fill prefix.
There is one special case where a change in indentation does not start
a new paragraph. This is for text of this form:
foo> This line with extra indentation starts
foo> a paragraph that continues on more lines.
These lines are filled together."
fill-nonuniform-paragraphs: "Fill paragraphs within the region, allowing varying indentation within each.
This command divides the region into "paragraphs",
only at paragraph-separator lines, then fills each paragraph
using as the fill prefix the smallest indentation of any line
in the paragraph."
Related
I am trying to display text over time using altair (vega-lite), which works fine using a layered chart, where one is created using the alt.Chart().mark_text() function to display the text.
The text though is multiple phrases and should be wrapped (with line breaks). How can this be done?
(I do not want to use fixed line breaks, e.g. \n, at distinct positions since the text wrapping should work with zooming too)
Not exactly what you want, but you can specify a character on which to break to a new line. When zooming, the text stays the same size, so it should always fit the view.
For example making a new line for every word:
.mark_text(lineBreak=' ')
I'm facing an issue with paragraph alignment after a list item. See the bitmap that makes it more clear:
Heading
First line
Bullet 1
Bullet 2
Second line is aligned with the list above. I did used two blank-lines to signify the end of list.
Org-Mode Paragraph Alignment
Any pointers are greatly appreciated.
This has nothing to do with org-mode: it's how LaTeX indents paragraphs after the first one (at least in the default styles); it does not happen when exporting to e.g., HTML.
For LaTeX, you can set the indent to 0 if you want all paragraphs to start at the left margin, by adding this to the top of your org file:
#+LATEX: \setlength{\parindent}{0pt}
When using Emacs's text mode, I find it handy to use the default indentation method with below features:
When I am at some indentation level, hitting C-j
will automatically bring me to the next line with identical
indentation level
When I hit Tab, the indentation will further right by some amount (usually to align with the next word in previous line)
However, I find it difficult to go back by one indentation level. E.g. If the current cursor is at the position of | as below:
Line 0: some text here
Line 1: some text here
Line 2: some text here
|Line 3: some text here
what can I do to bring the cursor to align with "L" in line 1?
Note the amount of spaces of each level indentation is not fixed, as it is usually align to the 2nd word of previous line. So it seems not proper to use reducing 4-spaces as indent to previous level.
Just curious whether there is any predefined / customized function for such purpose. It seems natural to seek for a corresponding "left-indent" command if the text-editor already provides a "right-indent" one.
This answer nicely provides a way to display characters rather than tabs (in the example it suggests ">", but I confirmed it works for ".").
It uses setting the active window display table to do it.
Now my goal is to display 4 spaces as 4 dots. Using the font-face and a regular expression, I am confident that I can display it nicely. I am aware that I could have Emacs automatically use tab characters rather than whitespaces, but I always prefer to have whitespace characters in my files.
I've also looked at whitespace mode, but I tweaked many parameters and in the end I never get the simple dots (with a face that makes it a little less "jump" out).
So: how can I, rather than display tab characters as dots, display 4 spaces elegantly as dots in Emacs?
OK, here's how to mark 4 or more spaces at beginning of line
(setq whitespace-space-regexp "^\\( \\{4,\\}\\)")
And here's how to get rid of the centered dot character for space:
(setq whitespace-display-mappings
'((space-mark ?\ [?\ ] [?.])
(space-mark ?\xA0 [?\ ] [?_])
(newline-mark ?\n [?$ ?\n])
(tab-mark ?\t [?\u00BB ?\t] [?\\ ?\t])))
The changes take effect not immediately but when you revert-buffer or
close it and open again with customizations above already set.
Being read about indent style, now I must change my current indent style from Banner Style, to Allman Style. I've changed the indent style using c-set-style and choosing bsd. But, now how do I apply the new indent style?
That is, can emacs reformat my code, and apply this new coding stye?
How can I configure emacs to use this sytle to be my java default style.
Thank you.
You can use indent-region to apply your indentation settings. If you want to re-indent the whole buffer, mark-whole-buffer (C-x h) followed by indent-region (C-M-\) should do it.
EDIT:
If you want to automatically move the braces onto their own lines, as in the style you cite, you'll have to do some regexp replacements as well. The following might be a start:
(query-replace-regexp "^\\([^{}\n]+[^{} \t\n]+[^{}\n]*\\)\\([{}]\\)$" "\\1\n\\2")
This will take any { or } character that is the last character on a line and put it on its own line. It will ignore any {} characters that are the first character on their lines. You may need to follow this with:
(query-replace-regexp "^\\(\\s *[{}]\\)\\(.+\\)$" "\\1\n\\2")
This will take any {} characters that are first on their line and are followed by other characters, and insert a newline between the brace and the other characters.
Following this, my original suggestion of mark-whole-buffer and indent-region should correct the indentation.
EDIT 2: fixed the first regexp to account for leading whitespace