[ESS-bugs] Font lock bugs in R mode
Ari Kornfeld
ari at perspective.com
Wed Feb 15 09:10:47 CET 2006
Tony, et. al.
Thanks for the reply. The idea of prompt being end-of-string/close
paren sounds great if it could be made into a "master close," i.e.
closes all unbalanced parens and quotes. It's well beyond my
skill/knowledge to do that, unfortunately.
On the other hand,here are all of the changes I made to ess-cust.el in
diff format. There are three basic changes
(1) Support for Mark Bravington's debug package (for S and R, but I
only use R): His debugger uses "D(xx)> " as a prompt.
(1A) Added parens to inferior-ess-primary-prompt, I also changed it in
essd-r.el, which overrides this variable with a constant.
The relevant line in essd-r.el is:
(inferior-ess-primary-prompt . "\\([A-Z][][()A-Za-z0-9.]*\\)*> ")
This change appears to be necessary for C-a to work correctly.
(1B) Modified font-lock-keyword-face so that package debug and the
built-in browse() ("Browse[xx]> ") prompts are fontified.
(2) Added a custom variable, ess-r-TF-is-const, and necessary logic as
you suggested. If set t, it highlights T and F as constants.
(3) Repositioned keywords so that warnings get fontified properly, as
we talked about before.
Best regards,
-ari
diff -c c:\Program Files\XEmacs\ess-5.2.12\lisp\ess-cust-orig.el
c:\Program Files\XEmacs\ess-5.2.12\lisp\ess-cust.el
*** c:\Program Files\XEmacs\ess-5.2.12\lisp\ess-cust-orig.el Tue Feb
14 23:49:20 2006
--- c:\Program Files\XEmacs\ess-5.2.12\lisp\ess-cust.el Tue Feb 14
23:49:20 2006
***************
*** 1053,1066 ****
:group 'ess-proc
:type 'string)
! (defcustom inferior-ess-primary-prompt "[a-zA-Z0-9() ]*> ?"
"Regular expression used by `ess-mode' to detect the primary prompt.
Do not anchor to bol with `^'."
:group 'ess-proc
:type 'string)
(make-variable-buffer-local 'inferior-ess-primary-prompt)
! (setq-default inferior-ess-primary-prompt "[a-zA-Z0-9() ]*> ?")
(defcustom inferior-ess-secondary-prompt "+ ?"
"Regular expression used by ess-mode to detect the secondary prompt.
--- 1053,1070 ----
:group 'ess-proc
:type 'string)
! ;; Ari (JAK) add brackets for "Browse [1]>"?
! ;; note: this doesn't affect font lock: see
inferior-ess-R-font-lock-keywords
! ;; note2: for R, at least, this value is ignored, see: essd-r.el
! (defcustom inferior-ess-primary-prompt "[][a-zA-Z0-9() ]*> ?"
"Regular expression used by `ess-mode' to detect the primary prompt.
Do not anchor to bol with `^'."
:group 'ess-proc
:type 'string)
(make-variable-buffer-local 'inferior-ess-primary-prompt)
! ; Ari (JAK) add brackets for "Browse [1]>"?
! (setq-default inferior-ess-primary-prompt "[][a-zA-Z0-9() ]*> ?")
(defcustom inferior-ess-secondary-prompt "+ ?"
"Regular expression used by ess-mode to detect the secondary prompt.
***************
*** 1321,1328 ****
:group 'ess
:type 'boolean)
(defvar ess-R-constants
! '("TRUE" "FALSE" "NA" "NULL" "Inf" "NaN"))
(defvar ess-S-constants
(append ess-R-constants '("T" "F")))
--- 1325,1342 ----
:group 'ess
:type 'boolean)
+ ;; Ari (JAK)
+ (defcustom ess-r-TF-is-const nil
+ "Let font-lock highlight T and F as constants."
+ :group 'ess-R
+ :type 'boolean)
+ ; add this to ~/.xemacs/init.el before loading ess site-init.el
+ ;(setq-default ess-r-TF-is-const t)
+
+ ; Ari: (JAK) add "T" and "F" since these *are* in R by default
(defvar ess-R-constants
! (append '("TRUE" "FALSE" "NA" "NULL" "Inf" "NaN")
! (if ess-r-TF-is-const '("T" "F"))))
(defvar ess-S-constants
(append ess-R-constants '("T" "F")))
***************
*** 1334,1348 ****
'("library" "attach" "detach" "source" "require"))
(defvar ess-R-keywords
! '("while" "for" "in" "repeat" "if" "else" "switch" "break" "next"
! "function" "return" "message" "warning" "stop"))
(defvar ess-S-keywords
(append ess-R-keywords '("terminate")))
(defvar ess-R-message-prefixes
'("Error:" "Error in"
! "Warning:" "Warning in"
! "Warning messages?"))
(defvar ess-S-message-prefixes
(append ess-R-message-prefixes
'("Syntax error:" "Dumped")))
--- 1348,1365 ----
'("library" "attach" "detach" "source" "require"))
(defvar ess-R-keywords
! '("while" "for" "repeat" "in" "if" "else" "switch" "break" "next"
! "function" "return" "warning" "message" "stop"))
(defvar ess-S-keywords
(append ess-R-keywords '("terminate")))
+ ;; Ari (JAK): The RE "Warning messages?" does not work.
+ ;; Cut off the "s?" and just added both variations
+ ;; (See also related fix in: ess-R-message-prefixes)
(defvar ess-R-message-prefixes
'("Error:" "Error in"
! "Warning:" "Warning in" "Warning message"
! "Warning messages"))
(defvar ess-S-message-prefixes
(append ess-R-message-prefixes
'("Syntax error:" "Dumped")))
***************
*** 1401,1417 ****
!
(defvar inferior-ess-R-font-lock-keywords
(append
! '(("^[a-zA-Z0-9 ]*[>+]" . font-lock-keyword-face)) ; "prompt" must
be first
(if (not inferior-ess-font-lock-input) ;; don't font-lock input :
(list (cons "^[a-zA-Z0-9 ]*[>+]\\(.*$\\)"
'(1 font-lock-variable-name-face keep t))) )
- ess-R-mode-font-lock-keywords
-
(list
(cons "^\\*\\*\\*.*\\*\\*\\*\\s *$" 'font-lock-comment-face);
ess-mode msg
(cons "\\[,?[1-9][0-9]*,?\\]"
'font-lock-reference-face);Vector/matrix labels
--- 1418,1436 ----
! ;; Ari (JAK) moved location of ess-R-mode-font-lock-keywords
! ;; so it doesn't override "Warning message" type of stuff
! ;; in ess-R-message-prefixes
! ;; + add brackets for "Browse [1]>" used in debug()/browse()
! ;; + add parens for package debug: "D(1)>"
(defvar inferior-ess-R-font-lock-keywords
(append
! '(("^[][()a-zA-Z0-9 ]*[>+]" . font-lock-keyword-face)) ; "prompt"
must be first
(if (not inferior-ess-font-lock-input) ;; don't font-lock input :
(list (cons "^[a-zA-Z0-9 ]*[>+]\\(.*$\\)"
'(1 font-lock-variable-name-face keep t))) )
(list
(cons "^\\*\\*\\*.*\\*\\*\\*\\s *$" 'font-lock-comment-face);
ess-mode msg
(cons "\\[,?[1-9][0-9]*,?\\]"
'font-lock-reference-face);Vector/matrix labels
***************
*** 1419,1437 ****
'font-lock-reference-face) ; inferior-ess problems or errors
(cons "#" 'font-lock-comment-face) ; comment
(cons "^[^#]*#\\(.*$\\)" '(1 font-lock-comment-face keep t)) ;
comments
! ))
"Font-lock patterns used in inferior-R-mode buffers.")
(defvar inferior-ess-S-font-lock-keywords
(append
! '(("^[a-zA-Z0-9 ]*[>+]" . font-lock-keyword-face)) ; "prompt" must
be first
(if (not inferior-ess-font-lock-input) ;; don't font-lock input :
(list (cons "^[a-zA-Z0-9 ]*[>+]\\(.*$\\)"
'(1 font-lock-variable-name-face keep t))) )
- ess-S-mode-font-lock-keywords
-
(list
(cons "^\\*\\*\\*.*\\*\\*\\*\\s *$" 'font-lock-comment-face) ;
ess-mode msg
(cons "\\[,?[1-9][0-9]*,?\\]"
'font-lock-reference-face);Vector/matrix labels
--- 1438,1461 ----
'font-lock-reference-face) ; inferior-ess problems or errors
(cons "#" 'font-lock-comment-face) ; comment
(cons "^[^#]*#\\(.*$\\)" '(1 font-lock-comment-face keep t)) ;
comments
! )
! ess-R-mode-font-lock-keywords
!
! )
"Font-lock patterns used in inferior-R-mode buffers.")
+ ;; Ari (JAK) moved location of ess-S-mode-font-lock-keywords
+ ;; so it doesn't override "Warning message" type of stuff
+ ;; in ess-S-message-prefixes
+ ;; + add parens for package debug: "D(1)>"
(defvar inferior-ess-S-font-lock-keywords
(append
! '(("^[()a-zA-Z0-9 ]*[>+]" . font-lock-keyword-face)) ; "prompt"
must be first
(if (not inferior-ess-font-lock-input) ;; don't font-lock input :
(list (cons "^[a-zA-Z0-9 ]*[>+]\\(.*$\\)"
'(1 font-lock-variable-name-face keep t))) )
(list
(cons "^\\*\\*\\*.*\\*\\*\\*\\s *$" 'font-lock-comment-face) ;
ess-mode msg
(cons "\\[,?[1-9][0-9]*,?\\]"
'font-lock-reference-face);Vector/matrix labels
***************
*** 1439,1445 ****
'font-lock-reference-face) ; inferior-ess problems or errors
(cons "#" 'font-lock-comment-face) ; comment
(cons "^[^#]*#\\(.*$\\)" '(1 font-lock-comment-face keep t)) ;
comments
! ))
"Font-lock patterns used in inferior-S-mode buffers.")
;; use the inferior-* ones directly in ess-trns.el
--- 1463,1472 ----
'font-lock-reference-face) ; inferior-ess problems or errors
(cons "#" 'font-lock-comment-face) ; comment
(cons "^[^#]*#\\(.*$\\)" '(1 font-lock-comment-face keep t)) ;
comments
! )
! ess-S-mode-font-lock-keywords
!
! )
"Font-lock patterns used in inferior-S-mode buffers.")
;; use the inferior-* ones directly in ess-trns.el
A.J. Rossini wrote:
> Please send to the ess-bugs list to keep the rest of the folks
> informed as well -- I'm not our local font-lock expert, and after a
> bit of hacking last week, won't have time for a few weeks.
>
> As I said, I agreed about the warnings issue, just not the T/F issue.
> If you can send the examples, we should look into that (the
> warnings), but by "agreement" I also agree that it isn't a simple
> problem. Perhaps some form of manual intervention, i.e. noting that
> a prompt is also a valid "end-of-string", would be the right thing.
>
> Also, if you do send the patch I mentioned, then we can put it in, and
> you don't have to "fix" every release!
>
> best,
> -tony
>
>
>
More information about the ESS-bugs
mailing list