用emacs编辑R的源文件。。
函数竟然木有高亮。。。
新加的包更木有高亮。。。
如何解决
如何配置emacs
用emacs编辑R的源文件。。
函数竟然木有高亮。。。
新加的包更木有高亮。。。
如何解决
如何配置emacs
在.emacs文件里使用颜色主题,比如
<br />
;;颜色主题<br />
(require 'color-theme)<br />
(color-theme-deep-blue)<br />
</p>回复 第2楼 的 刘思喆:
我使用了颜色主题
但是高亮每个主题都会高亮显示不同关键字吧。。。
我的是这种情况。。。
忘了使用的哪种颜色主题了。。。
另外新加包的高亮网上似乎也木有好的解决方案吧。。。
关键是函数。。。木有高亮。。。
[ESS] Customizing the Syntax Highlighting in RS. McKay Curtis smcurtis at stat.washington.edu
Thu Mar 25 18:21:25 CET 2010
* Previous message: [ESS] Emacs not recognizing the "*.r" and "*.q" files.
* Next message: [ESS] Customizing the Syntax Highlighting in R
* Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
I've finally figured out a less hackish way of customizing the syntax
highlighting in R. Unfortunately, Emacs's regular expression
implementation does not have "lookahead," so more words are
highlighted than I would prefer, specifically, options in functions
that happen to have the same name as an R function are also
highlighted. One way to avoid this is to include the opening
parenthesis in the regular expression for the syntax highlighting, but
the solution then becomes a problem --- having that opening
parenthesis highlighted is a minor annoyance. So if any one has any
bright ideas on how to fix that I would appreciate hearing them.
Anyway, here's how to customize the syntax highlighting for R:
1) Run the following lines of code in R. The R code will create a
text file with the names of all the functions in the base, stats, and
utils R packages. If you would like more syntax highlighting for
functions in other commonly used packages, you can add other packages
by modifying the code. The code stores the text file in the
".emacs.d" directory, but you can modify the code to store this file
wherever you prefer. (Truth be told, I don't really know what the
.emacs.d directory is really supposed to be used for... It just
magically appeared one day, so I use it.)
## Get R function names from packages base, stat, and utils
## and store them in a file for ESS to use for font locking / syntax
highlighting
obj <- do.call("c", sapply(c("package:base", "package:stats",
"package:utils"), objects, all.names=TRUE))
re <- "(^[^.[:alpha:][:digit:]]|<-|__)" # to remove "weird" functions
obj <- obj[-grep(re, obj)]
fpath <- file.path(Sys.getenv("HOME"), ".emacs.d", "R-function-names.txt")
write.table(obj, fpath, quote=FALSE, row.names=FALSE, col.names=FALSE)
2) Add the following lines of code to your .emacs file:
;; Read a whole file into list of lines
;; Author: Xah Lee
;; see http://xahlee.org/emacs/elisp_process_lines.html
(defun read-lines (file)
"Return a list of lines in FILE."
(with-temp-buffer
(insert-file-contents file)
(split-string
(buffer-string) "\n" t)
)
)
(add-hook 'ess-mode-hook
'(lambda()
(setq ess-my-extra-R-function-keywords
(read-lines "~/.emacs.d/R-function-names.txt"))
(setq ess-R-mode-font-lock-keywords
(append ess-R-mode-font-lock-keywords
(list (cons (concat "\\<" (regexp-opt
ess-my-extra-R-function-keywords 'enc-paren) "\\>")
'font-lock-function-name-face))))))
If you don't like the particular color, you can change the "
'font-lock-function-name-face " to something else (see the code in
ess-custom.el file).
3) Enjoy the dazzling display of colors in R.
On Sat, Nov 21, 2009 at 9:48 AM, S. McKay Curtis
来源:https://stat.ethz.ch/pipermail/ess-help/2010-March/005974.html
回复 第5楼 的 linkim:
试了一下,似乎还是木有解决函数高亮,装载时也木有出现错误。。。
似乎If you don't like the particular color, you can change the "
'font-lock-function-name-face " to something else
这句话,说自己要设定颜色。。。
我想我为什么不能高亮可能这步有啥出入。。。
其他的我都是照搬上面的。。。
emacs其实我也是初步,不过一般的操作都可以。。。
这个可以解决ESS buffer的高亮问题,也R编程文件的语法高亮,但是对于iESS buffer的高亮没有办法解决。
回复 第7楼 的 linkim:
谢谢。。。
我想的可能就是要iESS buffer的函数高亮。。。
似乎ESS出来这么久了,为啥还木有解决,或者以EMACS为R终端的人是少数。。。
无高亮,不好看。。。
可怜我这视觉系了。。。
今天找到这个方法:https://github.com/emacs-ess/ESS/issues/89
好用。