unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "Andreas Röhler" <andreas.roehler@online.de>
To: emacs-devel@gnu.org
Cc: Stefan Monnier <monnier@iro.umontreal.ca>, jidanni@jidanni.org
Subject: Re: shell-script indenting of &&, |
Date: Thu, 28 Feb 2008 14:07:45 +0100	[thread overview]
Message-ID: <200802281407.46516.andreas.roehler@online.de> (raw)
In-Reply-To: <87zltmkxpd.fsf@jidanni.org>

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

Am Mittwoch, 27. Februar 2008 20:26 schrieb jidanni@jidanni.org:
> >> 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

[-- Attachment #2: 20080228-sh-script.diff --]
[-- Type: text/x-diff, Size: 6897 bytes --]

diff -cb MY-PATH/emacs/20080227/emacs/lisp/progmodes/sh-script-sicherung.el MY-PATH/emacs/20080227/emacs/lisp/progmodes/sh-script.el
*** MY-PATH/emacs/20080227/emacs/lisp/progmodes/sh-script-sicherung.el	2008-02-28 13:07:01.000000000 +0100
--- MY-PATH/emacs/20080227/emacs/lisp/progmodes/sh-script.el	2008-02-28 13:22:10.000000000 +0100
***************
*** 2140,2146 ****
  		    n thing (point) rule val)))
      val))
  
- 
  (defun sh-get-indent-info ()
    "Return indent-info for this line.
  This is a list.  nil means the line is to be left as is.
--- 2140,2145 ----
***************
*** 2185,2202 ****
  	  ;; we still need to get previous line in case
  	  ;; sh-indent-comment is t (indent as normal)
  	  (setq align-point (sh-prev-line nil))
! 	  (setq have-result nil)
! 	  ))
!        ) ;; cond
! 
        (unless have-result
  	;; Continuation lines are handled specially
! 	(if (sh-this-is-a-continuation)
  	    (progn
                (setq result
!                     (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
--- 2184,2200 ----
  	  ;; we still need to get previous line in case
  	  ;; sh-indent-comment is t (indent as normal)
  	  (setq align-point (sh-prev-line nil))
! 	  (setq have-result nil)))) ;; cond
        (unless have-result
  	;; 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
***************
*** 2211,2217 ****
  	  (beginning-of-line)
  	  (skip-chars-forward " \t")
  	  (setq this-kw (sh-get-kw)))
- 
          ;; Handle "this" keyword:  first word on the line we're
  	;; calculating indentation info for.
  	(if this-kw
--- 2209,2214 ----
***************
*** 2224,2235 ****
  		  (setq have-result t)
  		  ;; set prev-line to continue processing remainder
  		  ;; of this line as a previous line
! 		  (setq prev-line-end (point))
! 		  ))))
! 
        (unless have-result
  	(setq prev-line-end (sh-prev-line 'end)))
- 
        (if prev-line-end
  	  (save-excursion
  	    ;; We start off at beginning of this line.
--- 2221,2229 ----
  		  (setq have-result t)
  		  ;; set prev-line to continue processing remainder
  		  ;; of this line as a previous line
! 		  (setq prev-line-end (point))))))
        (unless have-result
  	(setq prev-line-end (sh-prev-line 'end)))
        (if prev-line-end
  	  (save-excursion
  	    ;; We start off at beginning of this line.
***************
*** 2253,2268 ****
  		(or (bobp)
  		    (forward-char -1))
                  ;; FIXME: This charset looks too much like a regexp.  --Stef
! 		(skip-chars-forward "[a-z0-9]*?")
! 		)
  	       ((string-match "[])}]" x)
  		(setq x (sh-safe-forward-sexp -1))
  		(if x
  		    (progn
  		      (setq align-point (point))
  		      (setq result (append result
! 					   (list "aligned to opening paren")))
! 		      )))
  	       ((string-match "[[({]" x)
  		(sh-debug "Checking special thing: %s" x)
  		(if (setq val (sh-check-rule 2 x))
--- 2247,2260 ----
  		(or (bobp)
  		    (forward-char -1))
                  ;; FIXME: This charset looks too much like a regexp.  --Stef
! 		(skip-chars-forward "[a-z0-9]*?"))
  	       ((string-match "[])}]" x)
  		(setq x (sh-safe-forward-sexp -1))
  		(if x
  		    (progn
  		      (setq align-point (point))
  		      (setq result (append result
! 					   (list "aligned to opening paren"))))))
  	       ((string-match "[[({]" x)
  		(sh-debug "Checking special thing: %s" x)
  		(if (setq val (sh-check-rule 2 x))
***************
*** 2284,2317 ****
  		(unless (bolp)
  		  (forward-char -1)))
  	       (t
! 		(error "Don't know what to do with %s" x))
! 	       )
! 	      )	;; while
! 	    (sh-debug "result is %s" result)
! 	    )
  	(sh-debug "No prev line!")
! 	(sh-debug "result: %s  align-point: %s" result align-point)
! 	)
! 
        (if align-point
  	  ;; was: (setq result (append result (list (list t align-point))))
! 	  (setq result (append  (list (list t align-point)) result))
! 	)
        (sh-debug "result is now: %s" result)
- 
        (or result
  	  (setq result (list (if prev-line-end
                                   (list t prev-line-end)
                                 (list '= 'sh-first-lines-indent)))))
- 
        (if (eq result t)
  	  (setq result nil))
        (sh-debug  "result is: %s" result)
!       result
!       )	;; let
      ))
  
- 
  (defun sh-get-indent-var-for-line (&optional info)
    "Return the variable controlling indentation for this line.
  If there is not [just] one such variable, return a string
--- 2276,2299 ----
  		(unless (bolp)
  		  (forward-char -1)))
  	       (t
! 		(error "Don't know what to do with %s" x))))	;; while
! 	    (sh-debug "result is %s" result))
  	(sh-debug "No prev line!")
! 	(sh-debug "result: %s align-point: %s" result align-point))
        (if align-point
  	  ;; was: (setq result (append result (list (list t align-point))))
! 	  (setq result (append (list (list t align-point)) result)))
        (sh-debug "result is now: %s" result)
        (or result
  	  (setq result (list (if prev-line-end
                                   (list t prev-line-end)
                                 (list '= 'sh-first-lines-indent)))))
        (if (eq result t)
  	  (setq result nil))
        (sh-debug "result is: %s" result)
!       result)	;; let
      ))
  
  (defun sh-get-indent-var-for-line (&optional info)
    "Return the variable controlling indentation for this line.
  If there is not [just] one such variable, return a string
***************
*** 2529,2534 ****
--- 2511,2524 ----
  	 (looking-at ".*\\\\$")
  	 (not (nth 4 (parse-partial-sexp (match-beginning 0) (match-end 0)
  					 nil nil nil t))))))
+ (defun sh-short-if ()
+   "Return non-nil if current line ends with a `\&\&' or `\|\|'."
+   (save-excursion
+     (and (zerop (forward-line -1))
+ 	 (or (looking-at ".*&&[ \t]*$")
+ 	     (looking-at ".*||[ \t]*$"))
+ 	 (not (nth 4 (parse-partial-sexp (match-beginning 0) (match-end 0)
+ 					 nil nil nil t))))))
  
  (defun sh-get-kw (&optional where and-move)
    "Return first word of line from WHERE.

Diff finished.  Thu Feb 28 13:29:52 2008

  reply	other threads:[~2008-02-28 13:07 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.7016.1202258720.18990.bug-gnu-emacs@gnu.org>
2008-02-26 23:37 ` shell-script indenting of &&, | jidanni
2008-02-27  6:52   ` David Kastrup
2008-02-27  7:15   ` Andreas Röhler
2008-02-27 15:51     ` Stefan Monnier
2008-02-27 19:26       ` jidanni
2008-02-28 13:07         ` Andreas Röhler [this message]
2008-02-29  8:04           ` Andreas Röhler
2008-02-29 21:12             ` Chong Yidong
2008-02-29 21:15               ` Chong Yidong
2008-03-01  7:48                 ` David Kastrup
2008-03-01 13:27                 ` Andreas Röhler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200802281407.46516.andreas.roehler@online.de \
    --to=andreas.roehler@online.de \
    --cc=emacs-devel@gnu.org \
    --cc=jidanni@jidanni.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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).