Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing Emacs to indent (shift 4) code
    primarykey
    data
    text
    <p>I edit my StackOverflow answers and questions with <a href="http://dafizilla.sourceforge.net/viewsourcewith/" rel="nofollow noreferrer">ViewSourceWith</a> and Emacs. Often, I include code and <a href="https://stackoverflow.com/editing-help">StackOverflow formatting rules</a> say that it must be indented by four spaces to be recognized as such. Doing it by hand or even with macros is painful.</p> <p>I searched in SO's previous postings but found nothing.</p> <p>Starting from the Python mode, I wrote:</p> <pre><code>(defun text-shift-region (start end count) "Indent lines from START to END by COUNT spaces." (save-excursion (goto-char end) (beginning-of-line) (setq end (point)) (goto-char start) (beginning-of-line) (setq start (point)) (indent-rigidly start end count))) (defun text-shift-region-right (start end &amp;optional count) "Shift region of code to the right Stolen from python-mode. The lines from the line containing the start of the current region up to (but not including) the line containing the end of the region are shifted to the right, by `text-indent-offset' columns. If a prefix argument is given, the region is instead shifted by that many columns. With no active region, indent only the current line." (interactive (let ((p (point)) (m (mark)) (arg current-prefix-arg)) (if m (list (min p m) (max p m) arg) (list p (save-excursion (forward-line 1) (point)) arg)))) (text-shift-region start end (prefix-numeric-value (or count text-indent-offset))) ) ;; Code in StackOverflow must be marked by four spaces at the ;; beginning of the line (setq text-indent-offset 4) (global-set-key "\C-c&gt;" 'text-shift-region-right) </code></pre> <p>It seems to work but I welcome advices, alternatives, bug reports, etc.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload