help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Indent one level deeper rather than smart indent?


From: Aleš Bizjak
Subject: Re: Indent one level deeper rather than smart indent?
Date: Fri, 22 Mar 2013 21:12:38 +0100



On 22 March 2013 17:06, Andrew Pennebaker <andrew.pennebaker@gmail.com> wrote:
When in markdown-mode, I would like to disable smart indent. Instead, when I highlight a block of code and press TAB, I would like the block to be indented one level deeper, like how Sublime does it.

What goes in my ~/.emacs to achieve this?


Which markdown-mode are you using? If the one at http://jblevins.org/projects/markdown-mode/ then I think something like

(defadvice markdown-cycle (around indent-active-region-rigidly (&optional arg shift) activate)
  (if (use-region-p)
      (save-excursion
        (let ((rb (region-beginning))
              (re (region-end)))
          (goto-char rb)
          (beginning-of-line)
          (indent-rigidly (point)
                          re 
                          (if shift (- tab-width) tab-width))
          (setq deactivate-mark nil)))
    ad-do-it))

should do it. If you don't have an active region TAB will behave the same as before, but if you have an active region, it will indent the whole region for tab-width. I have never used sublime-text so I don't know whether this is what you actually want. If you always want to indent and never want to cycle the visibility then the solution is simpler.

If you want Shift+TAB to indent regions to the left then also put

(add-hook 'markdown-mode-hook
          (lambda ()
            (fset 'markdown-shifttab 
                  (lambda () 
                    (interactive)
                    (markdown-cycle t t)))))

into your .emacs. 

-- Cheers, Aleš

reply via email to

[Prev in Thread] Current Thread [Next in Thread]