~ubuntu-branches/ubuntu/wily/ess/wily

« back to all changes in this revision

Viewing changes to lisp/ess-roxy.el

  • Committer: Package Import Robot
  • Author(s): Dirk Eddelbuettel
  • Date: 2013-12-07 13:26:27 UTC
  • mto: This revision was merged to the branch mainline in revision 38.
  • Revision ID: package-import@ubuntu.com-20131207132627-mz1170cktcl0arck
Tags: upstream-13.09-1
ImportĀ upstreamĀ versionĀ 13.09-1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
;;; ess-roxy.el --- convenient editing of in-code roxygen documentation
 
1
; ess-roxy.el --- convenient editing of in-code roxygen documentation
2
2
;;
3
3
;; Copyright (C) 2009--2012 Henning Redestig, A.J. Rossini, Richard
4
4
;;      M. Heiberger, Martin Maechler, Kurt Hornik, Rodney Sparapani, Stephen
69
69
(defvar ess-roxy-mode-map
70
70
  (let ((map (make-sparse-keymap)))
71
71
    (if ess-roxy-hide-show-p
72
 
        (define-key map (kbd "C-c C-o h") 'ess-roxy-hide-all)) ;; dont bind C-h!!!!
 
72
        (define-key map (kbd "C-c C-o h") 'ess-roxy-hide-all))
73
73
    ;; short version (*first*: -> key binding shown in menu):
74
74
    (define-key map (kbd "C-c C-o n")   'ess-roxy-next-entry)
75
75
    (define-key map (kbd "C-c C-o p")   'ess-roxy-previous-entry)
76
76
    ;; For consistency (e.g. C-c C-o C-h !): kept here *in* addition to above
77
77
    (define-key map (kbd "C-c C-o C-o") 'ess-roxy-update-entry)
78
78
    (define-key map (kbd "C-c C-o C-r") 'ess-roxy-preview-Rd)
79
 
    (define-key map (kbd "C-c C-o C-t") 'ess-roxy-preview-HTML)
80
 
    (define-key map (kbd "C-c C-o t")   'ess-roxy-preview-text)
 
79
    (define-key map (kbd "C-c C-o C-w") 'ess-roxy-preview-HTML)
 
80
    (define-key map (kbd "C-c C-o C-t")   'ess-roxy-preview-text)
81
81
    (define-key map (kbd "C-c C-o C-c") 'ess-roxy-toggle-roxy-region)
82
82
    map)
83
83
  )
140
140
  (setq paragraph-start (concat "\\(" ess-roxy-re "\\)*" paragraph-start))
141
141
  (make-local-variable 'paragraph-separate)
142
142
  (setq paragraph-separate (concat "\\(" ess-roxy-re "\\)*" paragraph-separate))
 
143
  (add-hook 'ess-presend-filter-functions 'ess-roxy-remove-roxy-re nil 'local)
143
144
  )
144
145
 
145
146
 
521
522
    (delete-file tmpf)
522
523
    roxy-buf))
523
524
 
524
 
(defun ess-roxy-preview-HTML (&optional visit-instead-of-open)
 
525
(defun ess-roxy-preview-HTML (&optional visit-instead-of-browse)
525
526
  "Use a (possibly newly) connected R session and the roxygen package to
526
527
generate a HTML page for the roxygen entry at point and open that
527
528
buffer in a browser.  Visit the HTML file instead of showing it in
528
 
a browser if `visit-instead-of-open' is non-nil."
 
529
a browser if `visit-instead-of-browse' is non-nil."
529
530
  (interactive "P")
530
531
  (let* ((roxy-buf (ess-roxy-preview))
531
532
         (rd-tmp-file (make-temp-file "ess-roxy-" nil ".Rd"))
539
540
      (kill-buffer roxy-buf))
540
541
    (ess-force-buffer-current)
541
542
    (ess-command "print(suppressWarnings(require(tools, quietly=TRUE)))\n")
542
 
    (ess-command
543
 
     (if visit-instead-of-open
544
 
         (concat rd-to-html "\n")
545
 
       (concat "browseURL(" rd-to-html ")\n")))
546
 
    (find-file html-tmp-file)))
547
 
 
 
543
    (if visit-instead-of-browse
 
544
        (progn
 
545
          (ess-command (concat rd-to-html "\n"))
 
546
          (find-file html-tmp-file))
 
547
      (ess-command (concat "browseURL(" rd-to-html ")\n")))))
548
548
 
549
549
(defun ess-roxy-preview-text ()
550
550
  "Use the connected R session and the roxygen package to
657
657
      (when (and end (= end (point)))
658
658
        (list beg end (append ess-roxy-tags-noparam ess-roxy-tags-param) :exclusive 'no)))))
659
659
 
660
 
;; advices
 
660
(defun ess-roxy-remove-roxy-re (string)
 
661
  "Remove the `ess-roxy-str' before sending to R process. Useful
 
662
  for sending code from example section.  This function is placed
 
663
  in `ess-presend-filter-functions'.
 
664
  "
 
665
  (if (ess-roxy-entry-p)
 
666
      (replace-regexp-in-string ess-roxy-re "" string)
 
667
    string))
 
668
(add-hook 'ess-presend-filter-functions 'ess-roxy-remove-roxy-re nil)
 
669
 
661
670
(defadvice mark-paragraph (around ess-roxy-mark-field)
662
671
  "mark this field"
663
672
  (if (and (ess-roxy-entry-p) (not mark-active))