-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathr-utils.el
74 lines (65 loc) · 2.46 KB
/
r-utils.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
;;; r-utils.el --- Various utilities for R code -*- lexical-binding: t; -*-
;;
;; Copyright © 2016 Vitalie Spinu, Lionel Henry
;; Authors: Lionel Henry <[email protected]>,
;; Vitalie Spinu <[email protected]>
;; Created: 4 Jul 2016
;;
;; This file is not part of GNU Emacs.
;;
;;; License:
;;
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License
;; as published by the Free Software Foundation; either version 3
;; of the License, or (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
;;
;;; Code:
(defvar r-symbol-regexp "\\(\\sw\\|\\s_\\)"
"The regular expression for matching an R symbol")
(defun r-blink-region (start end)
(when ess-blink-region
(move-overlay ess-current-region-overlay start end)
(run-with-timer ess-blink-delay nil
(lambda ()
(delete-overlay ess-current-region-overlay)))))
(defun r-set-variables (alist &optional globalp)
"Set variables from ALIST in current buffer.
Each element of ALIST is of the form (SYM . VAL) where SYM is the
symbol to be assigned to, and VAL is an expression to be
evaluated. Evaluation is done with `eval'. If GLOBALP is
non-nil, set the default value of the variables."
(dolist (kv alist)
(let ((k (car kv))
(v (cdr kv)))
(if globalp
(set-default k (eval v))
(make-local-variable k)
(set k (eval v))))))
;;*;; Position Info
(defun r-looking-at (regex &optional newlines)
"Like `looking-at' but consumes blanks and comments first."
(save-excursion
(r-skip-blanks-forward newlines)
(looking-at regex)))
(defun r-line-end-position ()
"Like (line-end-position) but stops at comments"
(save-excursion
(or (and (re-search-forward "#" (line-end-position) t)
(match-beginning 0))
(line-end-position))))
(defun r-containing-sexp-position ()
"Return position of the containing sexp."
(cadr (syntax-ppss)))
(provide 'r-utils)
;;; r-utils.el ends here