Is there a good way to uniformly indent a block of text in an m4 macro? In other words, the macro
define(`mytext',dnl
This is
a
piece of text
that I would like
to indent)
mytext
generates
This is
a
piece of text
that I would like
to indent
I'd like to have a way to indent the whole block of text to a specified amount.
How about patsubst:
patsubst(mytext,`^', ` ')
Related
In code files, when I expand selection, brackets, quotes, and spaces are used to delimit "levels" of expansion.
However, when I'm working in plain text, expand selection ignores brackets and goes from selecting one word to then selecting a whole line.
Is there any way to have expand selection respect brackets and quotes in plain text files?
I'm authoring an extension for Racket (lisp dialect) and I'd like to customize the indentation rules further than just "when line ends with X, indentation +1, else indentation -1". However, as far as I understand it, that exactly is the point of increaseIndentPattern and decreaseIndentPattern in language-configuration.json.
In particular, I'd like to specify some rule that goes like this:
(call-foo first-arg
......... second-arg
......... (third-arg-function foo
..............................bar))
Where the dots denote the auto-indentation (spaces) automatically inserted by VS Code upon pressing return on the preceeding lines. Is it possible to do something like this?
I'm using codemirror for javascript code coloring, and when I put a string in quotes "like this" it is colored just fine.
But when I put a string with a line break "like
this" the color is messed up on the second line.
Is there any way to make sure the color starts with the first quote and ends with the second quote, even if there is a line break?
JavaScript doesn't allow multi-line strings. You can use a backslash before the newline, or use template literals (backtick-quoted strings), but if you don't, you aren't writing valid JavaScript, and that is the reason why the CodeMirror mode doesn't highlight your code as you expected.
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."
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