36 votes
Accepted

How to prettify/format an XML buffer?

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-| ...
  • 5,554
30 votes

How to prettify/format an XML buffer?

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-...
  • 19.5k
21 votes
Accepted

How prettify (newlines and indentation) an optimized HTML/JS file?

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. M-x sgml-pretty-print To ...
  • 24.5k
20 votes
Accepted

Org mode - Parsing rich HTML directly when pasting?

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 ...
  • 3,928
20 votes

Why does *compilation* buffer show control characters?

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 ...
20 votes
Accepted

Make org-mode markup symbols invisible?

If your question is specifically about org-mode and its emphasis markup: try customizing org-hide-emphasis-markers. You can set that to t to hide the markers around words in bold, italics, etc.
  • 19.5k
16 votes
Accepted

Can I format cells in an org-mode table differently depending on a formula?

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: #+name: item-prices |-------...
14 votes

Command that formats (prettifies) Elisp code

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)) (b (do-something))) (setq someone me) ...
  • 13.6k
14 votes

Command that formats (prettifies) Elisp code

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 ...
  • 70.9k
12 votes
Accepted

Automatically formatting brackets

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 ...
  • 25.5k
10 votes
Accepted

How to auto-format the source code block in org-mode

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. Cheers. (defun indent-...
  • 2,360
9 votes

How to prettify/format an XML buffer?

Mark your xml and do: M-x sgml-pretty-print Or just run the command without a marked region to prettify the whole buffer.
  • 91
8 votes
Accepted

"Format Code" like in Eclipse

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....
  • 2,290
8 votes
Accepted

Library that converts a Python output string to an Elisp data structure?

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 ...
  • 5,529
8 votes
Accepted

Formatting of usepackage commands in LaTeX document

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 ...
  • 3,225
7 votes
Accepted

Automatically formatting SQL code

Emacs does not come anything useful for sql indenting. The best thing out there is sql-indent.el Which doesn't do auto-indenting only on command indentation. I have found it pretty useful at times
7 votes
Accepted

Print message in echo area with no "quotes"?

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 ...
  • 14.3k
7 votes

Automatically formatting brackets

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 ...
  • 1,078
7 votes

How to prettify/format an XML buffer?

write this into your ~/.emacs.d/init.el: (require 'sgml-mode) (defun ninrod/reformat-xml () (interactive) (save-excursion (sgml-pretty-print (point-min) (point-max)) (indent-region (...
  • 1,286
6 votes

Can I format cells in an org-mode table differently depending on a formula?

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 ...
  • 1,795
6 votes
Accepted

Make emacs format Java more consistently

Set option indent-tabs-mode to nil: Put this in your init file, to make Emacs always indent using SPC characters, never TAB characters. (setq-default indent-tabs-mode nil)
  • 70.9k
6 votes

Automatically formatting SQL code

If you don't mind calling out to a python process, then this works (pip install sqlparse): (defun sqlparse-region (beg end) (interactive "r") (shell-command-on-region beg end "python -c '...
  • 196
6 votes
Accepted

Incrementing characters in Emacs, next to numbers?

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 ...
  • 70.9k
6 votes

I want to make format out its result to a variable instead of printing it

#'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) ...
  • 8,639
5 votes

Print message in echo area with no "quotes"?

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 ...
  • 5,924
5 votes
Accepted

Editing Fortran90 in a fixed format mode

Yes, there is nothing to stop you from using F90 highlighting in fortran-mode. Just put something like this in your config: (require 'f90) (add-hook 'fortran-mode-hook 'f90-font-lock-2) where the ...
  • 2,745
5 votes
Accepted

Transform selected text like a Python macro

This method will take the selected lines, wrap them in single quotes, and put them inside a list. (defun lines-to-list (point mark) (interactive "r") (let ((text (buffer-substring point mark))) ...
  • 8,639
5 votes
Accepted

How to set project-specific javscript indentation using js2-mode

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 ....
  • 463
5 votes
Accepted

Why does M-x underline-region doesn't work?

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 ...
5 votes
Accepted

clang-format malfunctioning(?) Or am I not fully understanding how clang-format works?

I found the same thing (not following my styles as defined in a .clang-format file, which happens to be in the parent directory in my case), and I think that the problem is in the way that the assume-...

Only top scored, non community-wiki answers of a minimum length are eligible