unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Re: shell-script indenting of &&, |
       [not found] <mailman.7016.1202258720.18990.bug-gnu-emacs@gnu.org>
@ 2008-02-26 23:37 ` jidanni
  2008-02-27  6:52   ` David Kastrup
  2008-02-27  7:15   ` Andreas Röhler
  0 siblings, 2 replies; 11+ messages in thread
From: jidanni @ 2008-02-26 23:37 UTC (permalink / raw)
  To: emacs-devel

RMS told me to send this here.
In shell-script mode, shouldn't lines 2, 3, and 4 be somewhat indented?
1 who
2 k=/cf && mountpoint -q $k/ && cd $k &&
3 find *norblewitz -mtime -1 -type f ! -name \*~|
4 cpio -vo|gzip > /var/tmp/cfBAK.`date +%u`.gz
5 mailq




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

* Re: shell-script indenting of &&, |
  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
  1 sibling, 0 replies; 11+ messages in thread
From: David Kastrup @ 2008-02-27  6:52 UTC (permalink / raw)
  To: jidanni; +Cc: emacs-devel

jidanni@jidanni.org writes:

> RMS told me to send this here.
> In shell-script mode, shouldn't lines 2, 3, and 4 be somewhat indented?
> 1 who
> 2 k=/cf && mountpoint -q $k/ && cd $k &&
> 3 find *norblewitz -mtime -1 -type f ! -name \*~|
> 4 cpio -vo|gzip > /var/tmp/cfBAK.`date +%u`.gz
> 5 mailq

Why line 2?

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum




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

* Re: shell-script indenting of &&, |
  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
  1 sibling, 1 reply; 11+ messages in thread
From: Andreas Röhler @ 2008-02-27  7:15 UTC (permalink / raw)
  To: emacs-devel; +Cc: jidanni

Am Mittwoch, 27. Februar 2008 00:37 schrieb jidanni@jidanni.org:
> RMS told me to send this here.
> In shell-script mode, shouldn't lines 2, 3, and 4 be somewhat indented?
> 1 who
> 2 k=/cf && mountpoint -q $k/ && cd $k &&
> 3 find *norblewitz -mtime -1 -type f ! -name \*~|
> 4 cpio -vo|gzip > /var/tmp/cfBAK.`date +%u`.gz
> 5 mailq


Line 2 must not, as it's top level IMO.

As `&&' may be considered as if-then form, I would
welcome indentation for lines 3 and 4.

Respective following ||

Thanks

Andreas Röhler




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

* Re: shell-script indenting of &&, |
  2008-02-27  7:15   ` Andreas Röhler
@ 2008-02-27 15:51     ` Stefan Monnier
  2008-02-27 19:26       ` jidanni
  0 siblings, 1 reply; 11+ messages in thread
From: Stefan Monnier @ 2008-02-27 15:51 UTC (permalink / raw)
  To: Andreas R\x1fFFFFFFhler; +Cc: jidanni, emacs-devel

>> RMS told me to send this here.
>> In shell-script mode, shouldn't lines 2, 3, and 4 be somewhat indented?
>> 1 who
>> 2 k=/cf && mountpoint -q $k/ && cd $k &&
>> 3 find *norblewitz -mtime -1 -type f ! -name \*~|
>> 4 cpio -vo|gzip > /var/tmp/cfBAK.`date +%u`.gz
>> 5 mailq

> Line 2 must not, as it's top level IMO.

> As `&&' may be considered as if-then form, I would
> welcome indentation for lines 3 and 4.

> Respective following ||

Agreed.  Patches welcome,


        Stefan




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

* Re: shell-script indenting of &&, |
  2008-02-27 15:51     ` Stefan Monnier
@ 2008-02-27 19:26       ` jidanni
  2008-02-28 13:07         ` Andreas Röhler
  0 siblings, 1 reply; 11+ messages in thread
From: jidanni @ 2008-02-27 19:26 UTC (permalink / raw)
  To: emacs-devel

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




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

* Re: shell-script indenting of &&, |
  2008-02-27 19:26       ` jidanni
@ 2008-02-28 13:07         ` Andreas Röhler
  2008-02-29  8:04           ` Andreas Röhler
  0 siblings, 1 reply; 11+ messages in thread
From: Andreas Röhler @ 2008-02-28 13:07 UTC (permalink / raw)
  To: emacs-devel; +Cc: Stefan Monnier, jidanni

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

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

* Re: shell-script indenting of &&, |
  2008-02-28 13:07         ` Andreas Röhler
@ 2008-02-29  8:04           ` Andreas Röhler
  2008-02-29 21:12             ` Chong Yidong
  0 siblings, 1 reply; 11+ messages in thread
From: Andreas Röhler @ 2008-02-29  8:04 UTC (permalink / raw)
  To: emacs-devel; +Cc: Stefan Monnier, jidanni

Am Donnerstag, 28. Februar 2008 14:07 schrieb Andreas Röhler:
> 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


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




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

* Re: shell-script indenting of &&, |
  2008-02-29  8:04           ` Andreas Röhler
@ 2008-02-29 21:12             ` Chong Yidong
  2008-02-29 21:15               ` Chong Yidong
  0 siblings, 1 reply; 11+ messages in thread
From: Chong Yidong @ 2008-02-29 21:12 UTC (permalink / raw)
  To: Andreas Röhler; +Cc: jidanni, Stefan Monnier, emacs-devel

Andreas Röhler <andreas.roehler@online.de> writes:

> As new (sh-short-if) is asked twice,
>
> it's probably cleaner to introduce a let.
>
> Below a diff of the region.

Looks OK.  If your testing works out, please check it into the trunk.
We can backport it to the branch after 22.2 is released.




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

* Re: shell-script indenting of &&, |
  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
  0 siblings, 2 replies; 11+ messages in thread
From: Chong Yidong @ 2008-02-29 21:15 UTC (permalink / raw)
  To: Andreas Röhler; +Cc: emacs-devel, Stefan Monnier, jidanni

Chong Yidong <cyd@stupidchicken.com> writes:

> Andreas Röhler <andreas.roehler@online.de> writes:
>
>> As new (sh-short-if) is asked twice,
>>
>> it's probably cleaner to introduce a let.
>>
>> Below a diff of the region.
>
> Looks OK.  If your testing works out, please check it into the trunk.
> We can backport it to the branch after 22.2 is released.

Whoops, I forgot: do you have a copyright assignment?




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

* Re: shell-script indenting of &&, |
  2008-02-29 21:15               ` Chong Yidong
@ 2008-03-01  7:48                 ` David Kastrup
  2008-03-01 13:27                 ` Andreas Röhler
  1 sibling, 0 replies; 11+ messages in thread
From: David Kastrup @ 2008-03-01  7:48 UTC (permalink / raw)
  To: Chong Yidong; +Cc: jidanni, Andreas Röhler, Stefan Monnier, emacs-devel

Chong Yidong <cyd@stupidchicken.com> writes:

> Chong Yidong <cyd@stupidchicken.com> writes:
>
>> Andreas Röhler <andreas.roehler@online.de> writes:
>>
>>> As new (sh-short-if) is asked twice,
>>>
>>> it's probably cleaner to introduce a let.
>>>
>>> Below a diff of the region.
>>
>> Looks OK.  If your testing works out, please check it into the trunk.
>> We can backport it to the branch after 22.2 is released.
>
> Whoops, I forgot: do you have a copyright assignment?

As a maintainer, you should be able to check

/fencepost.gnu.org:/home/g/gnuorg/copyright.list

No point in asking each time.  All the best.

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum




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

* Re: shell-script indenting of &&, |
  2008-02-29 21:15               ` Chong Yidong
  2008-03-01  7:48                 ` David Kastrup
@ 2008-03-01 13:27                 ` Andreas Röhler
  1 sibling, 0 replies; 11+ messages in thread
From: Andreas Röhler @ 2008-03-01 13:27 UTC (permalink / raw)
  To: emacs-devel; +Cc: Chong Yidong, Stefan Monnier, jidanni

Am Freitag, 29. Februar 2008 22:15 schrieb Chong Yidong:
> Chong Yidong <cyd@stupidchicken.com> writes:
> > Andreas Röhler <andreas.roehler@online.de> writes:
> >> As new (sh-short-if) is asked twice,
> >>
> >> it's probably cleaner to introduce a let.
> >>
> >> Below a diff of the region.
> >
> > Looks OK.  If your testing works out, please check it into the trunk.
> > We can backport it to the branch after 22.2 is released.
>
> Whoops, I forgot: do you have a copyright assignment?

Sorry, no. IMO FSF is at the wrong path here: You can't 
defend freedom while taking resort to advocates. 

The freedom of the socalled reign of law is
the freedom of lawyers and judges exclusively, whereas
the people is foolished and cheated. AFAIK US have the
most people in prison from all countries in relation to
citizens. That's for that. I'm not going to feed that
machine.

Too I consider copyright a still bigger mistake than
patents here. Computing isn't about copyright at
all. In contrast to material world, where shortage and
price of material matters, with computers everything
might be done that way or another way.

BTW the change in concern IMO is a trivial one, just
extending already existing things. So copyright
question shouldn't arise either.

Thanks all

Andreas Röhler




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

end of thread, other threads:[~2008-03-01 13:27 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [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
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

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