[ESS-bugs] Re^2: Re: Patch: correctly indent #! and recognize Rscript
Martin Maechler
maechler at stat.math.ethz.ch
Sat Apr 10 20:55:44 CEST 2010
>>>>> "MM" == Martin Maechler <maechler at stat.math.ethz.ch>
>>>>> on Fri, 9 Apr 2010 15:31:29 +0200 writes:
MM> This was accidentally sent to ESS-bugs-owner at ... the
MM> mailbox of the ESS-bugs mailing list manager; not
MM> something I read daily.
MM> The patch looks fairly comprehensive, but as I'm not
MM> using "#!... Rscript or "littler" scripts, I'd be happy
MM> for someone else to test this.
I would still be.
But only now I've tried to *apply* the patch to the current
sources "started at it" a bit, use 'make' and for possible byte
compiler warnings, and then committed it.
I'm not 100% sure if the patch applied correctly.
Jeffrey, can you try using the ESS development version from the
https://svn.r-project.org/ESS/trunk/
or any other "littler" or "Rscript" script writers among us?
Thanks again, Jeff,
and regards!
Martin
> ------- start of forwarded message -------
> Return-Path: <mailman-bounces at stat.math.ethz.ch>
> MIME-Version: 1.0
> In-Reply-To: <mailman.3619.1270546701.4248.ess-bugs at stat.math.ethz.ch>
> References: <mailman.3619.1270546701.4248.ess-bugs at stat.math.ethz.ch>
> Message-ID: <t2z3c9b41e1004060802lcc077e61g89f01a869f171a1f at mail.gmail.com>
> Errors-To: mailman-bounces at stat.math.ethz.ch
> From: Jeffrey Arnold <jarnold7 at mail.rochester.edu>
> Sender: mailman-bounces at stat.math.ethz.ch
> To: ess-bugs-owner at stat.math.ethz.ch
> Subject: Re: Patch: correctly indent #! and recognize Rscript
> Date: Tue, 6 Apr 2010 11:02:12 -0400
> Hi, sorry about the earlier blank message.
> I noticed that ess S-mode had a few problems in its handling of R scripts
> that use the Rscript or littler interpreters: (1) ess-fancy-comments did not
> recognize the shebang and indented it as a '#' comment, and (2) R scripts
> that did not use end in an extension but had Rscript or littler as the
> interpreter after the shabang. I attached a svn patch that adds the Rscript
> and littler interpreters to the interpreter-mode-alist variable and changes
> the ess-indent-line and S-indent-line functions to recognize the shebang.
> Thank you for all your work on ess.
> Jeff
> ------------------------------
> Jeffrey Arnold
> Department of Political Science
> University of Rochester
> jarnold7 at mail.rochester.edu
> jeffrey.arnold at gmail.com
> Index: lisp/ess-mode.el
> ===============================================================
> --- lisp/ess-mode.el (revision 4284)
> +++ lisp/ess-mode.el (working copy)
> @@ -927,7 +927,8 @@ of the expression are preserved."
> ;;;*;;; Support functions for indentation
> (defun ess-comment-indent ()
> - (if (looking-at "###")
> + (if (or (looking-at "###")
> + (and (looking-at "#!") (= 1 (line-number-at-pos))))
> (current-column)
> (if (looking-at "##")
> (let ((tem (ess-calculate-indent)))
> @@ -949,25 +950,27 @@ Return the amount the indentation changed by."
> (setq indent (current-indentation)))
> (t
> (skip-chars-forward " \t")
> - (if (and ess-fancy-comments (looking-at "###"))
> - (setq indent 0))
> - (if (and ess-fancy-comments
> - (looking-at "#")
> - (not (looking-at "##")))
> - (setq indent comment-column)
> - (if (eq indent t) (setq indent 0))
> - (if (listp indent) (setq indent (car indent)))
> - (cond ((and (looking-at "else\\b")
> - (not (looking-at "else\\s_")))
> - (setq indent (save-excursion
> - (ess-backward-to-start-of-if)
> - (+ ess-else-offset (current-indentation)))))
> - ((= (following-char) ?})
> - (setq indent
> - (+ indent
> - (- ess-close-brace-offset ess-indent-level))))
> - ((= (following-char) ?{)
> - (setq indent (+ indent ess-brace-offset)))))))
> + (cond ((and ess-fancy-comments ;; ### or #! shebang
> + (or (looking-at "###")
> + (and (looking-at "#!") (= 1 (line-number-at-pos)))))
> + (setq indent 0))
> + ;; Single # comment
> + ((and ess-fancy-comments (looking-at "#") (not (looking-at "##")))
> + (setq indent comment-column))
> + (t
> + (if (eq indent t) (setq indent 0))
> + (if (listp indent) (setq indent (car indent)))
> + (cond ((and (looking-at "else\\b")
> + (not (looking-at "else\\s_")))
> + (setq indent (save-excursion
> + (ess-backward-to-start-of-if)
> + (+ ess-else-offset (current-indentation)))))
> + ((= (following-char) ?})
> + (setq indent
> + (+ indent
> + (- ess-close-brace-offset ess-indent-level))))
> + ((= (following-char) ?{)
> + (setq indent (+ indent ess-brace-offset))))))))
> (skip-chars-forward " \t")
> (setq shift-amt (- indent (current-column)))
> (if (zerop shift-amt)
> Index: lisp/ess-s-l.el
> ===============================================================
> --- lisp/ess-s-l.el (revision 4284)
> +++ lisp/ess-s-l.el (working copy)
> @@ -254,8 +254,8 @@ when \\[ess-toggle-S-assign-key] is called.")
> (defun S-comment-indent ()
> "Indentation for S comments."
> -
> - (if (looking-at "###")
> + (if (or (looking-at "###")
> + (and (looking-at "#!") (= 1 (line-number-at-pos))))
> (current-column)
> (if (looking-at "##")
> (let ((tem (S-calculate-indent)))
> @@ -277,25 +277,29 @@ Return the amount the indentation changed by."
> (setq indent (current-indentation)))
> (t
> (skip-chars-forward " \t")
> - (if (and ess-fancy-comments (looking-at "###"))
> - (setq indent 0))
> - (if (and ess-fancy-comments
> - (looking-at "#")
> - (not (looking-at "##")))
> - (setq indent comment-column)
> - (if (eq indent t) (setq indent 0))
> - (if (listp indent) (setq indent (car indent)))
> - (cond ((and (looking-at "else\\b")
> - (not (looking-at "else\\s_")))
> - (setq indent (save-excursion
> - (ess-backward-to-start-of-if)
> - (+ ess-else-offset (current-indentation)))))
> - ((= (following-char) ?})
> - (setq indent
> - (+ indent
> - (- ess-close-brace-offset ess-indent-level))))
> - ((= (following-char) ?{)
> - (setq indent (+ indent ess-brace-offset)))))))
> + (cond ((and ess-fancy-comments ;; ### or #!
> + (or (looking-at "###")
> + (and (looking-at "#!") (= 1 (line-number-at-pos)))))
> + (setq indent 0))
> + ;; Single # comment
> + ((and ess-fancy-comments (looking-at "#") (not (looking-at "##")))
> + (setq indent comment-column))
> + (t
> + (if (eq indent t)
> + (setq indent 0))
> + (if (listp indent)
> + (setq indent (car indent)))
> + (cond ((and (looking-at "else\\b")
> + (not (looking-at "else\\s_")))
> + (setq indent (save-excursion
> + (ess-backward-to-start-of-if)
> + (+ ess-else-offset (current-indentation)))))
> + ((= (following-char) ?})
> + (setq indent
> + (+ indent
> + (- ess-close-brace-offset ess-indent-level))))
> + ((= (following-char) ?{)
> + (setq indent (+ indent ess-brace-offset))))))))
> (skip-chars-forward " \t")
> (setq shift-amt (- indent (current-column)))
> (if (zerop shift-amt)
> Index: lisp/ess-site.el
> ===============================================================
> --- lisp/ess-site.el (revision 4284)
> +++ lisp/ess-site.el (working copy)
> @@ -259,6 +259,14 @@ between .s or .S files and assembly mode.
> )
> auto-mode-alist)))
> +;; Rscript and littler interpreters recognized
> +(setq interpreter-mode-alist
> + (append
> + '(("Rscript" . r-mode)
> + ("r" . r-mode)
> + )
> + interpreter-mode-alist))
> +
> ;; (1.4) Customize the dialects for your setup.
> ;;; AS OF ESS 5.1.14, if you are using Emacs 20.x, x>3, or XEmacs
> Index: lisp/ess-mode.el
> ===============================================================
> --- lisp/ess-mode.el (revision 4284)
> +++ lisp/ess-mode.el (working copy)
> @@ -927,7 +927,8 @@ of the expression are preserved."
> ;;;*;;; Support functions for indentation
> (defun ess-comment-indent ()
> - (if (looking-at "###")
> + (if (or (looking-at "###")
> + (and (looking-at "#!") (= 1 (line-number-at-pos))))
> (current-column)
> (if (looking-at "##")
> (let ((tem (ess-calculate-indent)))
> @@ -949,25 +950,27 @@ Return the amount the indentation changed by."
> (setq indent (current-indentation)))
> (t
> (skip-chars-forward " \t")
> - (if (and ess-fancy-comments (looking-at "###"))
> - (setq indent 0))
> - (if (and ess-fancy-comments
> - (looking-at "#")
> - (not (looking-at "##")))
> - (setq indent comment-column)
> - (if (eq indent t) (setq indent 0))
> - (if (listp indent) (setq indent (car indent)))
> - (cond ((and (looking-at "else\\b")
> - (not (looking-at "else\\s_")))
> - (setq indent (save-excursion
> - (ess-backward-to-start-of-if)
> - (+ ess-else-offset (current-indentation)))))
> - ((= (following-char) ?})
> - (setq indent
> - (+ indent
> - (- ess-close-brace-offset ess-indent-level))))
> - ((= (following-char) ?{)
> - (setq indent (+ indent ess-brace-offset)))))))
> + (cond ((and ess-fancy-comments ;; ### or #! shebang
> + (or (looking-at "###")
> + (and (looking-at "#!") (= 1 (line-number-at-pos)))))
> + (setq indent 0))
> + ;; Single # comment
> + ((and ess-fancy-comments (looking-at "#") (not (looking-at "##")))
> + (setq indent comment-column))
> + (t
> + (if (eq indent t) (setq indent 0))
> + (if (listp indent) (setq indent (car indent)))
> + (cond ((and (looking-at "else\\b")
> + (not (looking-at "else\\s_")))
> + (setq indent (save-excursion
> + (ess-backward-to-start-of-if)
> + (+ ess-else-offset (current-indentation)))))
> + ((= (following-char) ?})
> + (setq indent
> + (+ indent
> + (- ess-close-brace-offset ess-indent-level))))
> + ((= (following-char) ?{)
> + (setq indent (+ indent ess-brace-offset))))))))
> (skip-chars-forward " \t")
> (setq shift-amt (- indent (current-column)))
> (if (zerop shift-amt)
> Index: lisp/ess-s-l.el
> ===============================================================
> --- lisp/ess-s-l.el (revision 4284)
> +++ lisp/ess-s-l.el (working copy)
> @@ -254,8 +254,8 @@ when \\[ess-toggle-S-assign-key] is called.")
> (defun S-comment-indent ()
> "Indentation for S comments."
> -
> - (if (looking-at "###")
> + (if (or (looking-at "###")
> + (and (looking-at "#!") (= 1 (line-number-at-pos))))
> (current-column)
> (if (looking-at "##")
> (let ((tem (S-calculate-indent)))
> @@ -277,25 +277,29 @@ Return the amount the indentation changed by."
> (setq indent (current-indentation)))
> (t
> (skip-chars-forward " \t")
> - (if (and ess-fancy-comments (looking-at "###"))
> - (setq indent 0))
> - (if (and ess-fancy-comments
> - (looking-at "#")
> - (not (looking-at "##")))
> - (setq indent comment-column)
> - (if (eq indent t) (setq indent 0))
> - (if (listp indent) (setq indent (car indent)))
> - (cond ((and (looking-at "else\\b")
> - (not (looking-at "else\\s_")))
> - (setq indent (save-excursion
> - (ess-backward-to-start-of-if)
> - (+ ess-else-offset (current-indentation)))))
> - ((= (following-char) ?})
> - (setq indent
> - (+ indent
> - (- ess-close-brace-offset ess-indent-level))))
> - ((= (following-char) ?{)
> - (setq indent (+ indent ess-brace-offset)))))))
> + (cond ((and ess-fancy-comments ;; ### or #!
> + (or (looking-at "###")
> + (and (looking-at "#!") (= 1 (line-number-at-pos)))))
> + (setq indent 0))
> + ;; Single # comment
> + ((and ess-fancy-comments (looking-at "#") (not (looking-at "##")))
> + (setq indent comment-column))
> + (t
> + (if (eq indent t)
> + (setq indent 0))
> + (if (listp indent)
> + (setq indent (car indent)))
> + (cond ((and (looking-at "else\\b")
> + (not (looking-at "else\\s_")))
> + (setq indent (save-excursion
> + (ess-backward-to-start-of-if)
> + (+ ess-else-offset (current-indentation)))))
> + ((= (following-char) ?})
> + (setq indent
> + (+ indent
> + (- ess-close-brace-offset ess-indent-level))))
> + ((= (following-char) ?{)
> + (setq indent (+ indent ess-brace-offset))))))))
> (skip-chars-forward " \t")
> (setq shift-amt (- indent (current-column)))
> (if (zerop shift-amt)
> Index: lisp/ess-site.el
> ===============================================================
> --- lisp/ess-site.el (revision 4284)
> +++ lisp/ess-site.el (working copy)
> @@ -259,6 +259,14 @@ between .s or .S files and assembly mode.
> )
> auto-mode-alist)))
> +;; Rscript and littler interpreters recognized
> +(setq interpreter-mode-alist
> + (append
> + '(("Rscript" . r-mode)
> + ("r" . r-mode)
> + )
> + interpreter-mode-alist))
> +
> ;; (1.4) Customize the dialects for your setup.
> ;;; AS OF ESS 5.1.14, if you are using Emacs 20.x, x>3, or XEmacs
> On Tue, Apr 6, 2010 at 5:38 AM, <ess-bugs-owner at stat.math.ethz.ch> wrote:
>> After content filtering, the message was empty
>>
>>
>>
>> ---------- Forwarded message ----------
>> From: Jeffrey Arnold <jarnold7 at mail.rochester.edu>
>> To: ess-bugs <ess-bugs at stat.math.ethz.ch>
>> Date: Sun, 4 Apr 2010 18:00:22 -0400
>> Subject: Patch: correctly indent #! and recognize Rscript
>>
>>
> ------- end of forwarded message -------
> _______________________________________________
> ESS-bugs ESS-bugs at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/ess-bugs
> _______________________________________________
> ESS-core list: https://stat.ethz.ch/mailman/listinfo/ess-core
More information about the ESS-bugs
mailing list