[ESS-bugs] ess-mode 5.3.6; paragraph filling

tyler tyler.smith at mail.mcgill.ca
Mon Dec 31 02:11:00 CET 2007


Editing scripts in ESS, I find the way ess fills paragraphs to be a
little awkward. For example:

## A very important comment about the following code.
## Here's a second line.
x <- 1 + 1
y <- 2 + 3
long.command <- plot(sample(1:100, replace = TRUE), runif(100), main = 'a colourful plot of nonsense', type = 'p', col = sample(1:10, 100, replace = TRUE))

Hitting M-q with point at the end of the last line produces this mess:

## A very important comment about the following code.
## Here's a second line.  x <- 1 + 1 y <- 2 + 3 long.command <-
plot(sample(1:100, replace = TRUE), runif(100), main =
'a colourful plot of nonsense', type = 'p', col = sample(1:10, 100,
replace = TRUE))

It's a little better with auto-fill-mode, since the original input would
be presented as:

## A very important comment about the following code.
## Here's a second line.
x <- 1 + 1
y <- 2 + 3
long.command <- plot(sample(1:100, replace = TRUE), runif(100), main =
                     'a colourful plot of nonsense', type = 'p', col =
                     sample(1:10, 100, replace = TRUE))

However, modifying the body of long.command and invoking M-q to deal
with the alteration may produce more jumbled comments and code.

One way to fix this, or at least reduce the variety of situations where
it occurs, is to add an additional alternative to the paragraph-start
variable (essl-s.el, line 69):

original version:
(defvar R-editing-alist
  '((paragraph-start		  . (concat "\\s-*$\\|" page-delimiter))

modified:
(defvar R-editing-alist
  '((paragraph-start		  . (concat ".*<-\\|\\s-*$\\|" page-delimiter))

This change indicates that any line containing the R assignment operator
'<-' should be treated as the beginning of a new paragraph. This will
force M-q to behave appropriately in the situation described above. 

Commands without the <- operator may still get filled into preceding
comments, and filling in comments that include <- may misbehave.
However, in my code these are much rarer than having a comment
immediately preceeding a command that uses <-. Also, this won't help
anyone that prefers '=' to '<-', but since '=' gets used on the second
or subsequent lines of a command, it won't work as a paragraph-start
option.

I accept that this might just be a personal quirk of mine, and not of
general interest. My change can be accomplished without altering the
source code, of course. Currently I'm using the following in .emacs:

(add-hook 'ess-mode-hook 
	  (lambda () 
	    (auto-fill-mode 1)
	    (setq paragraph-start (concat paragraph-start "\\|.*<-"))))

Let me know if that's helpful, or if there are better ways to deal
with this issue.

Thanks,

Tyler


[ess-site.el]: ess-customize-alist=nil 
[ess-site.el _2_]: ess-customize-alist=nil 
(S): ess-s-versions-create making M-x defuns for 
 
(R): ess-r-versions-create making M-x defuns for 
 

(R): ess-dialect=nil, buf=*scratch*, start-arg=nil
 current-prefix-arg=nil
(inferior-ess 0): ess-start-args=--no-readline   
ess-setq-vars-default 0: ess-language=Initial, -dialect=nil, buf=nil, comint..echoes=nil, comint..sender=comint-simple-send
ess-setq-vars-default 1: ess-language=S, -dialect=R, buf=nil, comint..echoes=nil, comint..sender=comint-simple-send
(inf-ess 1): lang=S, dialect=R, tmp-dialect=R, buf=*scratch*
(inf-ess 1.1): procname=R temp-dialect=R, buf-name=*R* 
(inferior-ess) Method #3 start=/home/tyler/rworkingdirectory/ buf=*R*
(ess-setq-vars-LOCAL): language=S, dialect=R, buf=nil, comint..echoes=nil, comint..sender=comint-simple-send
(inf-ess 2.1): ess-language=S, ess-dialect=R buf=*R* 
(inf-ess 2.2): start args = --no-readline  , inf-ess-start-args=--no-readline   
(inf-ess finish [S(R), R(nil,nil)]
(ess-multi 0):  inf-ess-start-args=--no-readline  , comint-..echoes=nil
(i-ess 1): buf=*R*, lang=S, comint..echo=nil, comint..sender=comint-simple-send,
(i-ess 2): buf=*R*, lang=S, comint..echo=t, comint..sender=inferior-R-input-sender,
(ess-setq-vars-LOCAL): language=S, dialect=R, buf=nil, comint..echoes=t, comint..sender=inferior-R-input-sender
(i-ess 3): curr-buf=*R*, comint..echo=t, comint..sender=inferior-R-input-sender,
(ess-multi post inf-ess: start-args=--no-readline  , comint-echoes=t
(ess-multi 1):  start-args=--no-readline   
Making Process...Buf *R*, Proc R, Prog R
 Start File=nil, Args= --no-readline  .
(R): inferior-ess-language-start=options(STERM='iESS', editor='emacsclient')
 (ess-search-list: re-computing..) after 'search()
', point-max=193
(get-object-list R) ..--> (ess-get-modtime-list)
(ess-object-names obj=.GlobalEnv): no directory - trying names
(ess-object-names obj=package:stats): no directory - trying names
(ess-object-names obj=package:graphics): no directory - trying names
(ess-object-names obj=package:grDevices): no directory - trying names
(ess-object-names obj=package:utils): no directory - trying names
(ess-object-names obj=package:datasets): no directory - trying names
(ess-object-names obj=package:methods): no directory - trying names
(ess-object-names obj=Autoloads): no directory - trying names
(ess-object-names obj=package:base): no directory - trying names
ess-get-modtime-list: new alist of length 9
 (length alist) : 9
(ess-object-names obj=.GlobalEnv): no directory - trying names
 have re-read pos=1: -> length 2
(get-object-list R) ..--> (ess-get-modtime-list)
 (ess-search-list: re-computing..) after 'search()
', point-max=211
(ess-object-names obj=package:vegan): no directory - trying names
ess-get-modtime-list: new alist of length 10
 (length alist) : 10
(ess-object-names obj=.GlobalEnv): no directory - trying names
 have re-read pos=1: -> length 3
(get-object-list R) .. using existing ess-*-alist
 (length alist) : 10
(ess-object-names obj=.GlobalEnv): no directory - trying names
 have re-read pos=1: -> length 3
(ess-setq-vars-LOCAL): language=S, dialect=R, buf=nil, comint..echoes=nil, comint..sender=comint-simple-send
(get-object-list R) ..--> (ess-get-modtime-list)
 (ess-search-list: re-computing..) after 'search()
', point-max=211
ess-get-modtime-list: new alist of length 10
 (length alist) : 10
(ess-object-names obj=.GlobalEnv): no directory - trying names
 have re-read pos=1: -> length 5
(ess-setq-vars-LOCAL): language=S, dialect=R, buf=nil, comint..echoes=nil, comint..sender=comint-simple-send
(ess-mode-1): ess-language=S, ess-dialect=R buf=Rlog19Apr07.R 
(ess-mode-1.5): alist=((ess-local-customize-alist quote R-customize-alist) (ess-dialect . R) (ess-suffix . R) (ess-dump-filename-template ess-replace-regexp-in-string S$ ess-suffix ess-dump-filename-template-proto) (ess-mode-syntax-table . R-syntax-table) (ess-mode-editing-alist . R-editing-alist) (ess-change-sp-regexp . ess-R-change-sp-regexp) (ess-help-sec-regex . ess-help-R-sec-regex) (ess-help-sec-keys-alist . ess-help-R-sec-keys-alist) (ess-loop-timeout . ess-S-loop-timeout) (ess-cmd-delay . ess-R-cmd-delay) (ess-function-pattern . ess-R-function-pattern) (ess-object-name-db-file . ess-r-namedb.el) (ess-imenu-mode-function quote ess-imenu-R) (inferior-ess-program . inferior-R-program-name) (inferior-ess-objects-command . inferior-R-objects-command) (inferior-ess-font-lock-keywords . inferior-ess-R-font-lock-keywords) (inferior-ess-search-list-command . search()
) (inferior-ess-help-command . help("%s", htmlhelp=FALSE)
) (inferior-ess-help-filetype) (inferior-ess-exit-command . q()) (inferior-ess-exit-prompt . Save workspace image? [y/n/c]: ) (inferior-ess-primary-prompt . \([A-Z][][A-Za-z0-9.]*\)?> ) (inferior-ess-secondary-prompt . + ?) (inferior-ess-start-file) (inferior-ess-start-args . ) (ess-STERM . iESS) (ess-editor . R-editor) (ess-pager . R-pager) (ess-language . S) (inferior-ess-exit-command . q()
) (inferior-ess-language-start eval inferior-S-language-start) (comint-use-prompt-regexp-instead-of-fields . t)) 
(ess-mode-1.6): editing-alist=((paragraph-start concat \s-*$\| page-delimiter) (paragraph-separate concat \s-*$\| page-delimiter) (paragraph-ignore-fill-prefix . t) (require-final-newline . t) (comment-start . #) (comment-add . 1) (comment-start-skip . #+ *) (comment-column . 40) (indent-line-function quote S-indent-line) (parse-sexp-ignore-comments . t) (ess-set-style . ess-default-style) (ess-local-process-name) (ess-mode-syntax-table . S-syntax-table) (add-log-current-defun-header-regexp . ^\(.+\)\s-+<-[ 	
]*function) (font-lock-defaults quote (ess-R-mode-font-lock-keywords nil nil ((46 . w) (95 . w))))) 
(ess-setq-vars-LOCAL): language=S, dialect=R, buf=nil, comint..echoes=nil, comint..sender=comint-simple-send

Finished setting up ESS-mode.
(ess-setq-vars-LOCAL): language=S, dialect=S+6, buf=nil, comint..echoes=nil, comint..sender=comint-simple-send
(ess-setq-vars-LOCAL): language=S, dialect=R, buf=nil, comint..echoes=nil, comint..sender=comint-simple-send
(ess-mode-1): ess-language=S, ess-dialect=R buf=TylerFunctions.R 
(ess-mode-1.5): alist=((ess-local-customize-alist quote R-customize-alist) (ess-dialect . R) (ess-suffix . R) (ess-dump-filename-template ess-replace-regexp-in-string S$ ess-suffix ess-dump-filename-template-proto) (ess-mode-syntax-table . R-syntax-table) (ess-mode-editing-alist . R-editing-alist) (ess-change-sp-regexp . ess-R-change-sp-regexp) (ess-help-sec-regex . ess-help-R-sec-regex) (ess-help-sec-keys-alist . ess-help-R-sec-keys-alist) (ess-loop-timeout . ess-S-loop-timeout) (ess-cmd-delay . ess-R-cmd-delay) (ess-function-pattern . ess-R-function-pattern) (ess-object-name-db-file . ess-r-namedb.el) (ess-imenu-mode-function quote ess-imenu-R) (inferior-ess-program . inferior-R-program-name) (inferior-ess-objects-command . inferior-R-objects-command) (inferior-ess-font-lock-keywords . inferior-ess-R-font-lock-keywords) (inferior-ess-search-list-command . search()
) (inferior-ess-help-command . help("%s", htmlhelp=FALSE)
) (inferior-ess-help-filetype) (inferior-ess-exit-command . q()) (inferior-ess-exit-prompt . Save workspace image? [y/n/c]: ) (inferior-ess-primary-prompt . \([A-Z][][A-Za-z0-9.]*\)?> ) (inferior-ess-secondary-prompt . + ?) (inferior-ess-start-file) (inferior-ess-start-args . ) (ess-STERM . iESS) (ess-editor . R-editor) (ess-pager . R-pager) (ess-language . S) (inferior-ess-exit-command . q()
) (inferior-ess-language-start eval inferior-S-language-start) (comint-use-prompt-regexp-instead-of-fields . t)) 
(ess-mode-1.6): editing-alist=((paragraph-start concat \s-*$\| page-delimiter) (paragraph-separate concat \s-*$\| page-delimiter) (paragraph-ignore-fill-prefix . t) (require-final-newline . t) (comment-start . #) (comment-add . 1) (comment-start-skip . #+ *) (comment-column . 40) (indent-line-function quote S-indent-line) (parse-sexp-ignore-comments . t) (ess-set-style . ess-default-style) (ess-local-process-name) (ess-mode-syntax-table . S-syntax-table) (add-log-current-defun-header-regexp . ^\(.+\)\s-+<-[ 	
]*function) (font-lock-defaults quote (ess-R-mode-font-lock-keywords nil nil ((46 . w) (95 . w))))) 
(ess-setq-vars-LOCAL): language=S, dialect=R, buf=nil, comint..echoes=nil, comint..sender=comint-simple-send

Finished setting up ESS-mode.


Emacs  : GNU Emacs 22.1.1 (i686-pc-linux-gnu, X toolkit)
 of 2007-12-11 on blackbart
Package: ess-mode 5.3.6

current state:
==============
(setq
 ess-language "S"
 ess-dialect "R"
 ess-ask-for-ess-directory t
 ess-ask-about-transfile nil
 ess-directory nil
 ess-keep-dump-files "always"
 ess-source-directory "/tmp/"
 )



More information about the ESS-bugs mailing list