Skip to content

Commit

Permalink
[Fix #252] Improve roxygen prefix support
Browse files Browse the repository at this point in the history
  • Loading branch information
lionel- committed Nov 23, 2015
1 parent 68b7b9a commit 8d6e5ad
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 9 deletions.
3 changes: 3 additions & 0 deletions lisp/ess-custom.el
Expand Up @@ -1533,6 +1533,9 @@ to sweave the current noweb file and latex the result."
:type '(choice (const :tag "Off" nil)
(const :tag "On" t)))

(defvar ess-roxy-insert-prefix-on-newline t
"When non-nil, `ess-newline-and-indent' will make sure the new
line starts with the roxy prefix.")

; System variables

Expand Down
26 changes: 24 additions & 2 deletions lisp/ess-mode.el
Expand Up @@ -129,6 +129,14 @@
map)
"Keymap for `ess-mode'.")

;; Redefine substituted commands
(substitute-key-definition 'newline-and-indent
'ess-newline-and-indent
ess-mode-map global-map)

(substitute-key-definition 'indent-new-comment-line
'ess-indent-new-comment-line
ess-mode-map global-map)

(defvar ess-eval-map
(let ((map (make-sparse-keymap)))
Expand Down Expand Up @@ -379,8 +387,8 @@ Furthermore, \\[ess-set-style] command enables you to set up predefined ess-mode
indentation style. At present, predefined style are `BSD', `GNU', `K&R', `C++',
`CLB' (quoted from C language style)."
(setq alist (or alist
(buffer-local-value 'ess-local-customize-alist (current-buffer))
(error "Customise alist is not specified, nor ess-local-customize-alist is set.")))
(buffer-local-value 'ess-local-customize-alist (current-buffer))
(error "Customise alist is not specified, nor ess-local-customize-alist is set.")))
(unless is-derived
(kill-all-local-variables)) ;; NOTICE THIS! *** NOTICE THIS! *** NOTICE THIS! ***
(ess-setq-vars-local alist)
Expand Down Expand Up @@ -709,6 +717,20 @@ current function."

(define-obsolete-function-alias 'ess-narrow-to-defun 'ess-narrow-to-defun-or-para "15.09")

(defun ess-newline-and-indent ()
(interactive)
(cond ((string= ess-dialect "R")
(ess-roxy-newline-and-indent))
(t
(newline-and-indent))))

(defun ess-indent-new-comment-line ()
(interactive)
(cond ((string= ess-dialect "R")
(ess-roxy-indent-new-comment-line))
(t
(indent-new-comment-line))))


;;*;; Loading files

Expand Down
8 changes: 7 additions & 1 deletion lisp/ess-r-d.el
Expand Up @@ -474,10 +474,16 @@ Executed in process buffer."
(ad-activate 'fill-paragraph)
(ad-activate 'move-beginning-of-line)
(ad-activate 'back-to-indentation)
(ad-activate 'newline-and-indent)
(ad-activate 'ess-eval-line-and-step)
(if ess-roxy-hide-show-p
(ad-activate 'ess-indent-command))
(substitute-key-definition 'newline-and-indent
'ess-newline-and-indent
ess-mode-map global-map)

(substitute-key-definition 'indent-new-comment-line
'ess-indent-new-comment-line
ess-mode-map global-map)

(run-hooks 'R-mode-hook))

Expand Down
21 changes: 15 additions & 6 deletions lisp/ess-roxy.el
Expand Up @@ -850,15 +850,23 @@ list of strings."
(goto-char (match-end 0)))
ad-do-it))

(defadvice newline-and-indent (around ess-roxy-newline)
(defun ess-roxy-indent-new-comment-line ()
(if (not (ess-roxy-entry-p))
(indent-new-comment-line)
(ess-roxy-indent-on-newline)))

(defun ess-roxy-newline-and-indent ()
(if (or (not (ess-roxy-entry-p))
(not ess-roxy-insert-prefix-on-newline))
(newline-and-indent)
(ess-roxy-indent-on-newline)))

(defun ess-roxy-indent-on-newline ()
"Insert a newline in a roxygen field."
(cond
;; Not in roxy entry; do nothing
((not (ess-roxy-entry-p))
ad-do-it)
;; Point at beginning of first line of entry; do nothing
((= (point) (ess-roxy-beg-of-entry))
ad-do-it)
(newline-and-indent))
;; Otherwise: skip over roxy comment string if necessary and then
;; newline and then inset new roxy comment string
(t
Expand All @@ -867,9 +875,10 @@ list of strings."
(ess-back-to-roxy)
(point))))
(goto-char (max (point) point-after-roxy-string)))
ad-do-it
(newline-and-indent)
(insert (concat (ess-roxy-guess-str t) " ")))))


(provide 'ess-roxy)

;;; ess-roxy.el ends here
33 changes: 33 additions & 0 deletions test/literate/roxy.R
Expand Up @@ -45,3 +45,36 @@ NULL
##' aliqua. Ut enim ad minim veniam, quis nostrud exercitation
##' ullamco laboris nisi ut aliquip ex ea commodo consequat.
NULL


### 2 ----------------------------------------------------------------

##' ¶

##! (global-set-key (kbd "RET") 'newline-and-indent)
##! (substitute-key-definition 'newline-and-indent
##! 'ess-newline-and-indent
##! ess-mode-map global-map)
##! "RET"

##'
##' ¶

##> "RET"

##'
##'
##' ¶

##> (setq ess-roxy-insert-prefix-on-newline nil)
##> "RET"

##'
##'
##'

##! "M-j"

##'
##' ¶

0 comments on commit 8d6e5ad

Please sign in to comment.