unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Indent one level deeper rather than smart indent?
@ 2013-03-22 16:06 Andrew Pennebaker
  2013-03-22 20:12 ` Aleš Bizjak
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Pennebaker @ 2013-03-22 16:06 UTC (permalink / raw)
  To: Emacs Help

[-- Attachment #1: Type: text/plain, Size: 292 bytes --]

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?

-- 
Cheers,

Andrew Pennebaker
www.yellosoft.us

[-- Attachment #2: Type: text/html, Size: 466 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Indent one level deeper rather than smart indent?
  2013-03-22 16:06 Indent one level deeper rather than smart indent? Andrew Pennebaker
@ 2013-03-22 20:12 ` Aleš Bizjak
  2013-03-26 13:18   ` Andrew Pennebaker
  0 siblings, 1 reply; 3+ messages in thread
From: Aleš Bizjak @ 2013-03-22 20:12 UTC (permalink / raw)
  To: Andrew Pennebaker; +Cc: Emacs Help

[-- Attachment #1: Type: text/plain, Size: 1597 bytes --]

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š

[-- Attachment #2: Type: text/html, Size: 2472 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Indent one level deeper rather than smart indent?
  2013-03-22 20:12 ` Aleš Bizjak
@ 2013-03-26 13:18   ` Andrew Pennebaker
  0 siblings, 0 replies; 3+ messages in thread
From: Andrew Pennebaker @ 2013-03-26 13:18 UTC (permalink / raw)
  To: Emacs Help

[-- Attachment #1: Type: text/plain, Size: 2592 bytes --]

Thanks! I ended up using:

;; If mark exists, indent rigidly.
;; Otherwise, insert a hard or soft tab indentation.
(defun traditional-indent ()
  (interactive)
  (if mark-active
    (indent-rigidly (region-beginning) (region-end) tab-width)
    (indent-to-column tab-width)))
;; Inverse.
(defun traditional-outdent ()
  (interactive)
  (if mark-active
    (indent-rigidly (region-beginning) (region-end) (* tab-width -1))
    (delete-backward-char tab-width)))

(add-hook 'markdown-mode-hook
          (lambda ()
            (setq indent-tabs-mode nil)
            (setq tab-width 4)
            (define-key markdown-mode-map (kbd "<tab>") 'traditional-indent)
            (define-key markdown-mode-map (kbd "S-<tab>")
'traditional-outdent)))



On Fri, Mar 22, 2013 at 4:12 PM, Aleš Bizjak <ales.bizjak0@gmail.com> wrote:

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



-- 
Cheers,

Andrew Pennebaker
www.yellosoft.us

[-- Attachment #2: Type: text/html, Size: 15261 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-03-26 13:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-22 16:06 Indent one level deeper rather than smart indent? Andrew Pennebaker
2013-03-22 20:12 ` Aleš Bizjak
2013-03-26 13:18   ` Andrew Pennebaker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).