Does the functionality already exist to reformat this buffer to be somewhat user-readable?
Of course, and you have plenty of options. I'd probably feed it to an external program using:
C-x h C-u M-| xmllint --format - RET
This program comes with libxml2. You could also use tidy. Here's a list of commandline xml formatting tools: https://stackoverflow.com/...
The built-in sgml-mode has a command to do this: sgml-pretty-print. If you're in nxml-mode it looks like you need switch to sgml-mode first. You could write a command to temporarily switch to sgml-mode, run pretty-print, then switch back to nxml-mode.
For example, here is a command that will pretty-print the region, optionally with auto-fill enabled:
You can use the built-in sgml-mode for this.
M-x sgml-mode - Enable the sgml-mode major mode so that sgml-pretty-print command auto-loads.
C-x h - Select the whole buffer.
To save space, below is only a part of the formatted text that I get on doing the above on your sample text in the question:
<table border="4px" cellpadding="0" ...
These are indeed escape sequences which the terminal should interpret as orders to change the text color. Normally they shouldn't be used when the compiler is invoked from Emacs (the terminal type should be set to dumb, which should cause the compiler to refrain from using any escape sequence). There may be something wrong in your configuration that causes ...
is it feasible to make one?
Since this is emacs, yes.
My approach is to use a 3rd party tools that can take HTML and convert to plain text or even directly to Org format. I think this is an ugly hack, and there may be better ways to do this, but it looks like it works for my test cases.
(defun kdm/html2org-clipboard ()
"Convert clipboard contents from ...
Emacs-24.4's electric-pair-mode does one part of what you want already (this mode is very similar to autopair.el, not sure how it compares to smartparens).
And c-toggle-auto-newline does the other part.
But sadly they don't work right together. Please M-x report-emacs-bug so we can fix that.
Instead of c-toggle-auto-newline, you can also use electric-...
Here's how lispy re-formatted it for me
(by pressing M at either end of the expression):
(defun my-example-function ()
(let ((a (do-something))
(setq someone me)
(with-current-buffer b (do-that (or this (and that those)))
(format "%s" a))))
To get from this to the formatting that you specified, ...
As others have suggested in comments, "formatting" can mean different things.
For indentation that is pretty conventional, try using C-M-q (command indent-pp-sexp in Lisp modes) with the cursor somewhere inside the top-level sexp that you want to re-indent (e.g. the defun sexp).
No, this is not "automatic" indentation, but it can become a habit to use it. ;...
I got whole-table formatting to work with some Elisp:
A formula is evaluated for the cells' contents, and converted to a color using a gradient.
Org file including code:
| Item | Weight | Label Price | ...
You can use ClangFormat to achieve this. After installing the clang-format tool, you can use clang-format.el to perform the appropriate actions from emacs. clang-format.el is also available from MELPA. The emacs commands provided are clang-format-buffer and clang-format-region which you can bind as you need. Note that you can customize formatting options by ...
Use JSON, not Python syntax
What you are looking for is json.el which is a part of Emacs.
Note that it will not read Python format OOTB; there are at least 3 problems:
'foo' is not recognized as a string
keywords true/false/null are recognized instead of True/False/None
tuples (1,"bar") are not recognized
Full solution using json.dumps in Python
Solved. The sequence of cursor movements from my first version (in the original post) was funky.
As reference for future readers, the following code should work. It obv needs the Smartparens package (which you can get from git-hub). I'm running Emacs 24.4. It works with electric-indent mode enabled or disabled.
Below is a hard solution, but it works perfect. Actually it is just a function which simulations your operations, and use a run-at-time to make it be called every 10 seconds.
(defun indent-org-block-automatically ()
(indent-region (point-min) (point-max))
write this into your ~/.emacs.d/init.el:
(defun ninrod/reformat-xml ()
(sgml-pretty-print (point-min) (point-max))
(indent-region (point-min) (point-max))))
reload emacs, then just call M-x reformat-xml on the badly formatted xml buffer.
If you want a command to stay in a line on its own, add it to LaTeX-paragraph-commands:
(setq LaTeX-paragraph-commands '("documentclass" "usepackage"))
But, honestly, I didn't ever see anyone trying to fill the preamble ;-)
Characters are numbers (non-negative integers under some limit), in Emacs. If you want to increment a single character, including a digit character, then just increment it as a character:
(defun increment-char-at-point ()
"Increment number or character at point."
(let ((chr (1+ (char-...
#'format actually returns the formatted value; it doesn't print it out. However, many ways of evaluating code do print the returned value -- e.g., #'eval-last-sexp.
Here's some code (run in ielm) that saves the result to a variable, then checks that variable:
ELISP> (setq myvar (format "some %s here" "text"))
"some text here"
"some text ...
When you evaluate a function with M-:, the function gets run, and then its return value is displayed in the echo area. The return value of test-fn is the value returned by message, which is the string that was printed. Thus, though message did actually display the message, it was overwritten by M-: displaying the return value. (You can confirm that both ...
What you see printed in the echo area when evaluating the command is its return value - a string. The print syntax for strings includes quotation marks.
When you call the command non-interactively from another function/command, you shouldn't see the quotation marks:
(defun test-test-fn ()
Then call M-x test-test-fn RET to test....
Yes, there is nothing to stop you from using F90 highlighting in fortran-mode. Just put something like this in your config:
(add-hook 'fortran-mode-hook 'f90-font-lock-2)
where the number at the end (1 to 4) controls the degree of gaudiness. Here is an example with the default color scheme and f90-font-lock-4 (maximum gaudiness).
This method will take the selected lines, wrap them in single quotes, and put them inside a list.
(defun lines-to-list (point mark)
(let ((text (buffer-substring point mark)))
(delete-region point mark)
(insert (mapconcat (lambda (line) (format "'%s'" line))
(split-string text "\s*\n\s*")
Perhaps there is a dot-file that I can add to my project's root folder where I can configure settings?
Yes. It is called "Per-Directory Local Variables" aka ".dir-locals.el".
Create a file named .dir-locals.el in the project root directory and have project specific configurations in it. More info (https://www.emacswiki.org/emacs/DirectoryVariables)
It appears to work as advertised. Note that what looks like ^H in the emacs buffer is really a backspace character. If you were to print _^HS on an old fashioned dot matrix printer, it would print the underscore, then the print head would go back one step, and it would print the S. Result: an underlined S! And so on for the next characters.
Basically, this ...
Using an overlay is how I'm going to want to do it. I can hook into org-ctrl-c-ctrl-c-hook. It means I can press C-c C-c to run the check.
I need to properly check that I'm inside a table and run this for all cells.
Then I probably need to hook into the alignment function to either redo the overlays or at least clear them.
This code will make the cell ...
You can try reading the sexp and then printing with pp. The read function expects elisp syntax, so it's going to stumble on a few
special chars like ,'#. So you'll have to work around that.
Since your example included commas, here's a hacky snippet that works
(defun endless/pretty-print-sexp ()
"Pretty print the sexp after point.