From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andrew Pennebaker Newsgroups: gmane.emacs.help Subject: Re: Indent one level deeper rather than smart indent? Date: Tue, 26 Mar 2013 09:18:04 -0400 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=089e0111be2a62204304d8d3c0ea X-Trace: ger.gmane.org 1364303903 3207 80.91.229.3 (26 Mar 2013 13:18:23 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 26 Mar 2013 13:18:23 +0000 (UTC) To: Emacs Help Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Mar 26 14:18:50 2013 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UKTm4-00076n-QL for geh-help-gnu-emacs@m.gmane.org; Tue, 26 Mar 2013 14:18:49 +0100 Original-Received: from localhost ([::1]:55216 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKTlg-0004BC-St for geh-help-gnu-emacs@m.gmane.org; Tue, 26 Mar 2013 09:18:24 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:50043) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKTlS-00049c-LL for help-gnu-emacs@gnu.org; Tue, 26 Mar 2013 09:18:12 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UKTlN-0008DJ-9R for help-gnu-emacs@gnu.org; Tue, 26 Mar 2013 09:18:10 -0400 Original-Received: from mail-ie0-x231.google.com ([2607:f8b0:4001:c03::231]:33806) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UKTlN-0008CK-1G for help-gnu-emacs@gnu.org; Tue, 26 Mar 2013 09:18:05 -0400 Original-Received: by mail-ie0-f177.google.com with SMTP id tp5so4274252ieb.8 for ; Tue, 26 Mar 2013 06:18:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=5hcOYSb5hN3MSJj5NaOaVb4lbeVQRCLbiv3Po9uzSuY=; b=sfMwk5V8bcNFMdZeUdzw0eIMKsDiE71T5YW+GAWBunBMQo2UsiHawNl3uEElm6E2x5 6SBMAE+6LlVxgVgBqlXihB3fOCQ635QjaUqBM3JJqwbj2UHfzcjVn/axluGmooqWeRm4 vECd5SjV806eIbNpMrTKDrqpXQAd67asrWT0QJO6+SMHuo3CmwzKB/UbRMdqOmP4/wqG 48XCNIw7/28WiLIbJe0G7k9l0eoZZKz0DP3hUomBqBHAyB8IcjiKMvLffh08bdY17sH6 xRC4G8R9YutuSysyflrsSGdYKHYLYmDfI938TP1/pDDCfwJl7vKmq4a+Q8tyN3Epdz+K K5BQ== X-Received: by 10.50.7.69 with SMTP id h5mr1344960iga.69.1364303884196; Tue, 26 Mar 2013 06:18:04 -0700 (PDT) Original-Received: by 10.42.110.194 with HTTP; Tue, 26 Mar 2013 06:18:04 -0700 (PDT) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4001:c03::231 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:89763 Archived-At: --089e0111be2a62204304d8d3c0ea Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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 "") 'traditional-indent= ) (define-key markdown-mode-map (kbd "S-") 'traditional-outdent))) On Fri, Mar 22, 2013 at 4:12 PM, Ale=C5=A1 Bizjak = wrote: > > > On 22 March 2013 17:06, Andrew Pennebaker wr= ote: > >> 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 t= o >> 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=C5=A1 > --=20 Cheers, Andrew Pennebaker www.yellosoft.us --089e0111be2a62204304d8d3c0ea Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Thanks! I ended up using:

;; If mark = exists,= indent= rigidl= y.
;; Otherwise, insert a hard or soft = tab ind= entation.
(defun traditional-indent ()
=C2=A0=C2=A0(interactive)
=C2=A0=C2=A0(if mark-active
=C2=A0=C2=A0=C2=A0=C2=A0(indent-rigidly (region-beginning) (region-end) tab<= /span>-= width)<= /div>
=C2=A0=C2=A0=C2=A0=C2=A0(indent-to-column tab-width)))
;; Inverse.
(defun traditional-outdent ()
=C2=A0=C2=A0(interactive)
=C2=A0=C2=A0(if mark-active
=C2=A0=C2=A0=C2=A0=C2=A0(indent-rigidly (region-beginning) (region-end) (* <= span class=3D"" style=3D"margin:0px;padding:0px;border:0px">tab-width -1))
=C2=A0=C2=A0=C2=A0=C2=A0(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 "&= lt;tab>") 'traditional-indent)
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0(define-key markdown-mo= de-map = (kbd "S-<tab>&quo= t;) 'tradi= tional-outdent)))


O= n Fri, Mar 22, 2013 at 4:12 PM, Ale=C5=A1 Bizjak <ales.bizjak0@gmail.= com> wrote:


On 22 March 2013 17:06, Andrew Pennebaker <andrew.penne= baker@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 li= ke 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=C2=A0= h= ttp://jblevins.org/projects/markdown-mode/=C2=A0then I think something = like

(defadvice markdown-cycle (around indent-active-region-= rigidly (&optional arg shift) activate)
=C2=A0 (if (use-regio= n-p)
=C2=A0 =C2=A0 =C2=A0 (save-excursion
=C2=A0 =C2=A0= =C2=A0 =C2=A0 (let ((rb (region-beginning))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (re (region-end)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (goto-char rb)
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 (beginning-of-line)
=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 (indent-rigidly (point)
=C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 re=C2= =A0
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (if shift (- tab-width) tab-width))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (setq deactivate-mark nil)))
<= div>=C2=A0 =C2=A0 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 vis= ibility then the solution is simpler.

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

(add-hook 'markdown-mode-hook<= /div>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (lambda ()
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (fset 'markdown-shifttab=C2=A0
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (lambda= ()=C2=A0
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 (interactive)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (markdown-cycle t t)))))

into your .emacs.=C2=A0

-- Cheers, Ale= =C5=A1



--
C= heers,

Andrew Pennebaker
--089e0111be2a62204304d8d3c0ea--