emacs-devel
[Top][All Lists]
Advanced

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

Re: shell-script indenting of &&, |


From: Andreas Röhler
Subject: Re: shell-script indenting of &&, |
Date: Fri, 29 Feb 2008 09:04:12 +0100
User-agent: KMail/1.9.5

Am Donnerstag, 28. Februar 2008 14:07 schrieb Andreas Röhler:
> Am Mittwoch, 27. Februar 2008 20:26 schrieb address@hidden:
> > >> Line 2 must not, as it's top level IMO.
> >
> > oops.
> >
> > >> As `&&' may be considered as if-then form, I would
> > >> welcome indentation for lines 3 and 4.
> > >>
> > >> Respective following ||
> >
> > Anyways, backslash-newline continuation lines are indented. Just use
> > the same formula.
>
> Thanks for the hint.
>
> Indeed nearly all what had to be done was introducing a
> new function `sh-short-if'.
>
> It proceeds respectivly to `sh-this-is-a-continuation',
> which already handles the final "/".
>
> Patch attached.
>
> Andreas Röhler


As new (sh-short-if) is asked twice,

it's probably cleaner to introduce a let.

Below a diff of the region.

*** /tmp/ediff6188MQH   2008-02-29 08:54:43.000000000 +0100
--- /tmp/ediff6188ZaN   2008-02-29 08:54:43.000000000 +0100
***************
*** 1,24 ****
        ;; Continuation lines are handled specially
!       (let ((cont (sh-this-is-a-continuation))
!             (sh-if-short (sh-short-if)))
!         (if (or cont sh-if-short)
!             (progn
!               (setq result
!                     (if (and (not sh-if-short) 
!                              (save-excursion
!                                (beginning-of-line)
!                                (not (memq (char-before (- (point) 2)) '(?\s 
?\t)))))
!                         ;; By convention, if the continuation \ is not
!                         ;; preceded by a SPC or a TAB it means that the line
!                         ;; is cut at a place where spaces cannot be freely
!                         ;; added/removed.  I.e. do not indent the line.
!                         (list '(= nil))
!                       ;; We assume the line being continued is already
!                       ;; properly indented...
!                       ;; (setq prev-line-end (sh-prev-line))
!                       (setq align-point (sh-prev-line nil))
!                       (list '(+ sh-indent-for-continuation))))
!               (setq have-result t)))
          (beginning-of-line)
          (skip-chars-forward " \t")
          (setq this-kw (sh-get-kw)))
--- 1,23 ----
        ;; Continuation lines are handled specially
!       (if (or (sh-this-is-a-continuation)
!               (sh-short-if))
!           (progn
!               (setq result
!                     (if (and (not (sh-short-if)) 
!                        (save-excursion
!                           (beginning-of-line)
!                           (not (memq (char-before (- (point) 2)) '(?\s ?
\t)))))
!                         ;; By convention, if the continuation \ is not
!                         ;; preceded by a SPC or a TAB it means that the line
!                         ;; is cut at a place where spaces cannot be freely
!                         ;; added/removed.  I.e. do not indent the line.
!                         (list '(= nil))
!                       ;; We assume the line being continued is already
!                       ;; properly indented...
!                       ;; (setq prev-line-end (sh-prev-line))
!                       (setq align-point (sh-prev-line nil))
!                       (list '(+ sh-indent-for-continuation))))
!             (setq have-result t))
          (beginning-of-line)
          (skip-chars-forward " \t")
          (setq this-kw (sh-get-kw)))
 



Andreas Röhler




reply via email to

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