The Stack Overflow podcast is back! Listen to an interview with our new CEO.
23

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/...


17

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.


12

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: (...


12

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 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" ...


11

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 ...


11

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-...


10

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 ...


10

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) (with-current-buffer b (do-that (or this (and that those))) (format "%s" a)))) To get from this to the formatting that you specified, ...


8

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 ...


8

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. ;...


8

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 Python ...


7

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

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. (defun my-create-newline-and-allman-...


7

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-org-block-automatically () (when (org-in-src-block-p) (org-edit-special) (indent-region (point-min) (point-max)) (org-edit-src-exit))) (run-at-time ...


6

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)


6

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 (point-min) (point-max)))) reload emacs, then just call M-x reformat-xml on the badly formatted xml buffer. source: https://davidcapello.com/blog/emacs/reformat-...


6

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." (interactive) (condition-case nil (save-excursion (let ((chr (1+ (char-...


6

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 ;-)


6

#'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" ELISP> myvar "some text ...


5

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 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).


5

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))) (delete-region point mark) (insert "[") (insert (mapconcat (lambda (line) (format "'%s'" line)) (split-string text "\s*\n\s*") ...


5

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 ...


4

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 ...


4

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 with commas. (defun endless/pretty-print-sexp () "Pretty print the sexp after point. This ...


4

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 ...


4

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 () (interactive) (test-fn)) Then call M-x test-test-fn RET to test....


4

For autoformatting code you can use these packages: py-autopep8 py-isort web-beautify web-mode (optional) Autoremove trailing whitespaces and indent regions: (defun format-current-buffer() (indent-region (point-min) (point-max))) (defun untabify-current-buffer() (if (not indent-tabs-mode) (untabify (point-min) (point-max))) nil) (add-to-list '...


4

Description You should use regular expression replacement. I'll describe how I would do the replacement with swiper, the built-in isearch-forward-regexp would work in a similar way but with more keys. C-s (swiper). Enter .* C-q TAB .*. There is a single space on each side of the tab char in the middle. Under the hood, swiper translates the input string ".*...


4

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) You ...


4

Basil's answer covers the needs of the end-user. If you're writing elisp docstrings for other people, however, you (unfortunately) can't rely on everyone configuring text-quoting-style to grave, so when you need to ensure that quotes are not converted, you have to use an escaping syntax: (defun foo () "Something about \\='foo") Will ensure that, ...


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