[ESS] font-lock-keywords-case-fold-search in BUGS mode

S. McKay Curtis smcurtis at stat.washington.edu
Mon Mar 9 20:07:58 CET 2009

Hi Rodney,

Thanks for you insights and suggestions.

Regarding the highlighting of "i" when not followed by a "(":

I altered the regular expression for keywords in the essd-bugs.el
file.  The original version would highlight both the keyword and the
following open parenthesis "(".  I changed the regular expression to

   (cons (concat "\\<\\(for\\|cloglog\\|equals\\|exp\\|inprod\\|"

which now only highlights the keywords (and not the opening
parenthesis).  I apologize for not having mentioned this earlier! I
encountered this problem with "font-lock-keywords-case-fold-search" a
while back and have just now decided to submit it to the help (as I
have started working with BUGS again), so I forgot to mention that I
changed this regular expression.

I would think that changing this regular expression should not affect
the ability to set the variable "font-lock-keywords-case-fold-search"
within a hook, though.  I still get the behavior I expect once I
manually set the variable "font-lock-keywords-case-fold-search" to
"nil", but I can't seem to set this value with the ess-bugs-mode-hook.

I should upgrade to the latest version of ESS, though; thanks for
pointing this out.

Again, sorry for any confusion I've caused, Rodney (and Stephen).

Just so I clear up any confusion I may have caused, here is the
complete defvar statement in my essd-bugs.el file (with my
changes---mostly just adding "\\<" and "\\>" to each statement):

(defvar ess-bugs-font-lock-keywords
   ;; .bug files
   (cons "#.*\n"

   (cons "^[ \t]*\\<\\(model\\|const\\|data\\|inits\\|var\\)\\>"

   (cons "\\<in\\>"

   (cons (concat "\\<d\\(bern\\|beta\\|bin\\|cat\\|chisqr\\|"

   (cons (concat "\\<\\(for\\|cloglog\\|equals\\|exp\\|inprod\\|"

   ;; .bmd files
   (cons (concat "\\<\\(clear\\|checkpoint\\|compile\\|data\\|"
		 "out\\|q\\|save\\|stats\\|update\\)[ \t\n]*")
  "ESS[BUGS]: Font lock keywords."


On Mon, Mar 9, 2009 at 11:17 AM, Rodney Sparapani <rsparapa at mcw.edu> wrote:
> S. McKay Curtis wrote:
>> Hi Stephen,
>> Here is the particular file that I am working on:
>> model {
>>        for (i in 1:nS){
>>            for (j in 1:nI){ mn[i,j] <- mu[j] + lam[j]*theta[i] }
>>            Y[i,1:4] ~ dmnorm(mn[i,1:4],Pmat1[,])
>>            Y[i,5:8] ~ dmnorm(mn[i,5:8],Pmat2[,])
>>            }
>>        ##==================================================
>>        ## Priors for latent variables
>>        for (i in 1:nS){ theta[i] ~ dnorm(0,1) }
>>        ##==================================================
>>        ## Loadings and Intercepts
>>        for (j in 1:nI){ lam[j] ~ dnorm(0,1) T(0,) }
>>        for (j in 1:nI){ mu[j] ~ dnorm(0,1) }
>>        ##==================================================
>>        ## Priors for variance parameters
>>        Pmat1[1:4,1:4] ~ dwish(W[,],4)
>>        Sig1[1:4,1:4] <- inverse(Pmat1[,])
>>        Pmat2[1:4,1:4] ~ dwish(W[,],4)
>>        Sig2[1:4,1:4] <- inverse(Pmat2[,])
>> }
>> All keywords (like "for", "dnorm", etc.) are font locked as I would
>> expect them to be, *except* the subscript "i" is also font locked
>> (e.g. in Y[i,1:4]).  This is because "I" (capital i) is defined as a
>> keyword (because it's used in specifying truncated distributions like
>> "dnorm(0,1) I(0,)"), but because "font-lock-keywords-case-fold-search"
>> is set to "t" so the lower case "i" when used as an index is also
>> highlighted.  Similarly, if I were to type "FOR" (all caps) into this
>> buffer, it would also be highlighted.
>> I can get the syntax highlighting that I expect by setting the value
>> of font-lock-keywords-case-fold-search manually ("M-x set-variable
>> [RET] font-lock-keywords-case-fold-search [RET] nil"), but my attempt
>> to add a hook to do this automatically hasn't worked.
>> I am using GNU Emacs 22.3.1 and ESS 5.3.8.
>> Thanks again,
>> McKay
> Hi McKay:
> Quite frankly, none of this makes any sense.  I do agree that it is
> reminiscent of an Emacs 22.3 bug.  However, to get the behavior
> that you describe, Emacs 22.3 would have to be so horribly broken
> as to be nearly unusable.  For example, you mention that "i"
> is fontified as if it was the censoring function I(.,.).  However,
> that would require a left parentheses to follow the "i" and none
> does.  So, here's two things to try:
> 1) upgrade ESS to 5.3.11.  A good idea anyways, but not likely
> to help I'm guessing.
> 2) get rid of Emacs 22.3.  If it is as bad as it sounds, then
> I'm guessing this will fix it.
> --
> Rodney Sparapani      Center for Patient Care & Outcomes Research (PCOR)
> Sr. Biostatistician              http://www.mcw.edu/pcor
> 4 wheels good, 2 wheels better!  Medical College of Wisconsin (MCW)
> WWLD?:  What Would Lombardi Do?  Milwaukee, WI, USA

More information about the ESS-help mailing list