Skip to content

Commit

Permalink
Generate keywords lazily
Browse files Browse the repository at this point in the history
  • Loading branch information
lionel- committed Jul 30, 2018
1 parent b6d4ab8 commit f354cf6
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 18 deletions.
5 changes: 5 additions & 0 deletions doc/newfeat.texi
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
Changes and New Features in development version:
@itemize @bullet

@item @ESS: Font-lock keywords are now generated lazily. That means you
can now add or remove keywords from variables like @code{ess-R-keywords}
in your Emacs config after loading ESS (i.e. in the @code{:config}
section for @code{use-package} users).

@item @ESS{[R]}: Interaction with inferior process in non-R files within
packages (for instance C or C++ files) has been improved. This is a work
in progress.
Expand Down
36 changes: 18 additions & 18 deletions lisp/ess-custom.el
Original file line number Diff line number Diff line change
Expand Up @@ -2768,46 +2768,46 @@ default or not."

;;; fl-keywords R
(defvar ess-R-fl-keyword:modifiers
(cons (concat "\\(" (regexp-opt ess-R-modifyiers 'words) "\\)\\s-*(")
'(1 ess-modifiers-face)) ; modify search list or source (i.e. directives)
'(eval . (cons (concat "\\(" (regexp-opt ess-R-modifyiers 'words) "\\)\\s-*(")
'(1 ess-modifiers-face)))
"Font-lock keyword R modifiers.")

(defvar ess-R-fl-keyword:fun-defs
(cons ess-R-function-name-regexp
'(1 font-lock-function-name-face nil))
'(eval . (cons ess-R-function-name-regexp
'(1 font-lock-function-name-face nil)))
"Font-lock keyword - function defintions for R.")

(defvar ess-r--bare-keywords
'("in" "else" "break" "next" "repeat"))

(defvar ess-R-fl-keyword:bare-keywords
(cons (regexp-opt ess-r--bare-keywords 'words)
'ess-keyword-face)
'(eval . (cons (regexp-opt ess-r--bare-keywords 'words)
'ess-keyword-face))
"Font-lock keywords that do not precede an opening parenthesis.")

(defvar ess-R-fl-keyword:keywords
(let ((function-kwords
(delq nil
(mapcar (lambda (k) (unless (member k ess-r--bare-keywords) k))
ess-R-keywords))))
(cons (concat "\\(" (regexp-opt function-kwords 'words) "\\)\\s-*(")
'(1 ess-keyword-face)))
'(eval . (let ((function-kwords
(delq nil
(mapcar (lambda (k) (unless (member k ess-r--bare-keywords) k))
ess-R-keywords))))
(cons (concat "\\(" (regexp-opt function-kwords 'words) "\\)\\s-*(")
'(1 ess-keyword-face))))
"Font-lock keywords that precede an opening parenthesis.")

(defvar ess-R-fl-keyword:control-flow-keywords
(cons (concat "\\(" (regexp-opt ess-R-control-flow-keywords 'words) "\\)\\s-*(")
'(1 ess-r-control-flow-keyword-face)))
'(eval . (cons (concat "\\(" (regexp-opt ess-R-control-flow-keywords 'words) "\\)\\s-*(")
'(1 ess-r-control-flow-keyword-face))))

(defvar ess-R-fl-keyword:signal-keywords
(cons (concat "\\(" (regexp-opt ess-R-signal-keywords 'words) "\\)\\s-*(")
'(1 ess-r-signal-keyword-face)))
'(eval . (cons (concat "\\(" (regexp-opt ess-R-signal-keywords 'words) "\\)\\s-*(")
'(1 ess-r-signal-keyword-face))))

(defvar ess-R-fl-keyword:assign-ops
(cons (regexp-opt ess-R-assign-ops) 'ess-assignment-face)
'(eval . (cons (regexp-opt ess-R-assign-ops) 'ess-assignment-face))
"Font-lock assign operators.")

(defvar ess-R-fl-keyword:constants
(cons (regexp-opt ess-R-constants 'words) 'ess-constant-face)
'(eval . (cons (regexp-opt ess-R-constants 'words) 'ess-constant-face))
"Font-lock constants keyword.")

(defvar ess-R-fl-keyword:F&T
Expand Down
30 changes: 30 additions & 0 deletions test/literate/fontification.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,33 @@ foo <-¶ foo <<-¶ foo ->¶ foo ->>¶ foo
TRUEFALSENANULLInfNaN
NA_integer_NA_real_NA_complex_NA_character_


### 8 Can modify keywords --------------------------------------------

foobar foobaz()

##! (let ((ess-R-keywords (append '("foobaz") ess-R-keywords)))
##> (ess-r-mode)
##> (font-lock-ensure))
##> (should (not (face-at-point)))
##> (forward-word)
##> (forward-char)

foobar ¶foobaz()

##> (should (eq (face-at-point) 'ess-keyword-face))

foobar ¶foobaz()


### 9 Can set keywords variable to nil -------------------------------

¶stop()

##! (let (ess-R-control-flow-keywords)
##> (ess-r-mode)
##> (font-lock-ensure))
##> (should (not (face-at-point)))

¶stop()

0 comments on commit f354cf6

Please sign in to comment.