[ESS-bugs] ess-mode 5.11; recognizing function definitions

Christophe Rhodes csr21 at cantab.net
Mon Aug 23 21:02:23 CEST 2010


Hi,

I've found it useful to set defun-prompt-regexp in ess-mode (which I
use exclusively for R) to a value, to allow beginning-of-defun and
end-of-defun to work.  In particular, for me, the value
  "^\\(\\(\\sw\\|\\s_\\)+\\|\\s\"\\S\"+\\s\"\\)\\s-*\\(=\\|<-\\)\\s-*function\\s-*(.*)\\s-*"
works reasonably well; the outer alternation in the first group is to
catch both
  ordinary_token <- function(...) { ... }
and
  `complicated:syntax<-` <- function(...) { ... }

At the moment I have this in an ess-mode-hook, but it seems
potentially to be generally useful.

Relatedly, I have also an additional entry in font-lock-keywords, in
order to fontify the `complicated:syntax<-` function name properly.
At the moment, function name fontification is built up in
ess-R-common-font-lock-keywords, using ess-R-function-name-regexp in
ess-custom.el; I'd suggest replacing those lines by

  (defvar ess-R-function-name-regexps
    (list
      "\\(\\(\\sw\\|\\s_\\)+\\)\\s-*\\(<-\\)\\(\\s-\\|\n\\)*function"
      "\\s\"\\(\\S\"+\\)\\s\"\\s-*\\(<-\\)\\(\\s-\\|\n\\)*function"))

and then using

  (mapcar (lambda (x) (cons x '(1 font-lock-function-name-face t)))
          ess-R-function-name-regexps)

in the definition of ess-R-common-font-lock-keywords.

I'm happy to discuss these suggestions further, but please Cc me, as I
am not subscribed to the bugs list.

Best wishes,

Christophe

[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 
 
(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=swank.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 . inferior-ess-r-help-command)
(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-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=R, buf=nil,
comint..echoes=nil, comint..sender=comint-simple-send
(ess-mode-1): ess-language=S, ess-dialect=R buf=swank.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 . inferior-ess-r-help-command)
(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-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-BEG-of-fun after 'search-FWD (': Ini-pt 7570, (p)-Ini-pt = 6
ELSE  not in setMethod() header ...
      Match,Pt:(6995,7021),6995
      Match,Pt:(5871,5906),5871
      Match,Pt:(5833,5863),5833
      Match,Pt:(5488,5511),5488
      Match,Pt:(5180,5212),5180
      Match,Pt:(4642,4663),4642
      Match,Pt:(4597,4621),4597
      Match,Pt:(4186,4208),4186
      Match,Pt:(4059,4087),4059
      Match,Pt:(3608,3626),3608
      Match,Pt:(3555,3586),3555
      Match,Pt:(3411,3433),3411
      Match,Pt:(3255,3278),3255
      Match,Pt:(2712,2750),2712
      Match,Pt:(2374,2405),2374
      Match,Pt:(2310,2343),2310
      Match,Pt:(1911,1932),1911
      Match,Pt:(1591,1617),1591
      Match,Pt:(1244,1260),1244
      Match,Pt:(1002,1023),1002
      Match,Pt:(755,779),755
      Match,Pt:(563,584),563
      Match,Pt:(469,493),469
      Match,Pt:(345,366),345
      Match,Pt:(303,321),303
      Match,Pt:(143,173),143
      Match,Pt:(68,91),68
      Match,Pt:(1,19),1


Emacs  : GNU Emacs 23.1.1 (i486-pc-linux-gnu, GTK+ Version 2.18.2)
 of 2009-11-02 on raven, modified by Debian
Package: ess-mode 5.11

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