~ubuntu-branches/ubuntu/raring/ess/raring-proposed

« back to all changes in this revision

Viewing changes to lisp/tmp/ess-rlib.el

  • Committer: Package Import Robot
  • Author(s): Dirk Eddelbuettel
  • Date: 2012-05-09 08:00:38 UTC
  • mfrom: (1.2.23)
  • Revision ID: package-import@ubuntu.com-20120509080038-7an3nhbtgaj02a17
Tags: 12.04-1-1
New upstream patch version released today

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
;; the functions within a package.  Use RET or mouse-2 to click on a
6
6
;; link and see either contents of a package or the function.
7
7
;;
8
 
;; To use, simply start a R session, eval this buffer, 
9
 
;; then, in the R buffer, do 
 
8
;; To use, simply start a R session, eval this buffer,
 
9
;; then, in the R buffer, do
10
10
;; source("ess-rlib.R")
11
11
;; to load the changes to the data() and print.libraryIQR() functions.
12
12
;;
20
20
;; okay, but fails on "S3 read functions"
21
21
;;
22
22
;; (ess-rpackage "eda")
23
 
;; shows help for lib, but won't show individual files unless package 
 
23
;; shows help for lib, but won't show individual files unless package
24
24
;; has been loaded.  How to show help without loading the package first?
25
25
 
26
26
;; (ess-rpackage "ts")
31
31
;; one problem, near end of buffer.
32
32
 
33
33
;; Presumably, adding link markup to the output from library() command
34
 
;; would help here so that only functions will get converted into 
 
34
;; would help here so that only functions will get converted into
35
35
;; links.  This would be more robust than using regexps.
36
36
 
37
37
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
55
55
contents for loaded packages only.  This calls an extra R funcition named
56
56
funs.for.package()."
57
57
  (interactive (let ()
58
 
                 (list 
59
 
                  (completing-read "Package name: "  
60
 
                                   (mapcar 'list
61
 
                                           (ess-rpackage-list))))))
 
58
                 (list
 
59
                  (completing-read "Package name: "
 
60
                                   (mapcar 'list
 
61
                                           (ess-rpackage-list))))))
62
62
  (let (beg str (all t))
63
63
    (setq str (concat "funs.for.package('"
64
 
                      package
65
 
                      "')\n"))
 
64
                      package
 
65
                      "')\n"))
66
66
    (ess-execute str nil "ess-rlib")
67
67
    (pop-to-buffer "*ess-rlib*")
68
68
    (goto-char (point-min))
70
70
      (beginning-of-line)
71
71
      (setq beg (point))
72
72
      (re-search-forward "\\s-")
73
 
      (add-text-properties beg (1- (point)) 
74
 
                           '(face underline
75
 
                                  mouse-face highlight
76
 
                                  help-xref function))
 
73
      (add-text-properties beg (1- (point))
 
74
                           '(face underline
 
75
                                  mouse-face highlight
 
76
                                  help-xref function))
77
77
      ))
78
 
  
 
78
 
79
79
  ;; End of mark up, so add some text to the top of buffer.
80
80
  (goto-char (point-min))
81
81
  (insert "Functions in package " package ":\n\n")
89
89
    (ess-execute "cat(.packages(), '\\n')")
90
90
    (pop-to-buffer "*ess-output*")
91
91
    (cdr (reverse
92
 
          (split-string (buffer-substring (point-min) (point-max)) " ")))))
 
92
          (split-string (buffer-substring (point-min) (point-max)) " ")))))
93
93
 
94
94
 
95
95
(defun ess-rpackage-1 (lib)
102
102
  ;; todo: would it be worth getting completion for package list?
103
103
  (let (beg str (all t))
104
104
    (setq str
105
 
          (if (equal lib "")
106
 
              "library()"
107
 
            (setq all nil)
108
 
            (concat "library(help="
109
 
                    lib
110
 
                    ")\n")))
 
105
          (if (equal lib "")
 
106
              "library()"
 
107
            (setq all nil)
 
108
            (concat "library(help="
 
109
                    lib
 
110
                    ")\n")))
111
111
    (ess-execute str nil "ess-rlib")
112
112
    (pop-to-buffer "*ess-rlib*")
113
 
    (if all 
114
 
        (ess-markup-libnames)
 
113
    (if all
 
114
        (ess-markup-libnames)
115
115
      (re-search-forward "^Index:")
116
116
      (while (re-search-forward "^[^ ]+ " nil t)
117
 
        (beginning-of-line)
118
 
        (setq beg (point))
119
 
        (re-search-forward "[ \t]")
120
 
        (add-text-properties beg (1- (point)) 
121
 
                             '(     face underline
122
 
                                       mouse-face highlight
123
 
                                       help-xref function))
124
 
      (end-of-line)
125
 
      ))
 
117
        (beginning-of-line)
 
118
        (setq beg (point))
 
119
        (re-search-forward "[ \t]")
 
120
        (add-text-properties beg (1- (point))
 
121
                             '(     face underline
 
122
                                         mouse-face highlight
 
123
                                         help-xref function))
 
124
        (end-of-line)
 
125
        ))
126
126
 
127
127
    ;; end of mark up
128
128
    (goto-char (point-min))
139
139
    (search-forward "}")
140
140
    (delete-backward-char 1)
141
141
    (add-text-properties beg (point)
142
 
                         '(face underline
143
 
                                mouse-face highlight
144
 
                                help-xref library))
 
142
                         '(face underline
 
143
                                mouse-face highlight
 
144
                                help-xref library))
145
145
    (end-of-line)))
146
146
 
147
147
 
151
151
  (while (re-search-forward "^[^ ]+ " nil t)
152
152
    (beginning-of-line)
153
153
    (if (not (looking-at "Packages in library"))
154
 
        (progn
155
 
          (setq beg (point))
156
 
          (re-search-forward "[ \t]")
157
 
          (add-text-properties beg (1- (point)) 
158
 
                               '(face underline
159
 
                                      mouse-face highlight
160
 
                                      help-xref library))))
161
 
          (end-of-line)
162
 
          ))
 
154
        (progn
 
155
          (setq beg (point))
 
156
          (re-search-forward "[ \t]")
 
157
          (add-text-properties beg (1- (point))
 
158
                               '(face underline
 
159
                                      mouse-face highlight
 
160
                                      help-xref library))))
 
161
    (end-of-line)
 
162
    ))
163
163
 
164
164
 
165
165
;;; Set up the major mode for viewing.
186
186
(defun ess-rpackage-show-help ()
187
187
  "Show ESS help  for item on current line."
188
188
  (interactive)
189
 
  (let 
 
189
  (let
190
190
      (beg fn type)
191
191
    (save-excursion
192
192
      (beginning-of-line)
193
193
      (setq beg (point))
194
194
      (if (looking-at "[ \t\n]")
195
 
          (message "No function on this line.")
196
 
        (setq type (get-text-property (point) 'help-xref))
197
 
        (re-search-forward "\\s-")
198
 
        (setq fn (buffer-substring-no-properties beg (1- (point))))
199
 
        (if (equal type 'function)
200
 
            (ess-display-help-on-object fn)
201
 
          (ess-rpackage fn))))))
 
195
          (message "No function on this line.")
 
196
        (setq type (get-text-property (point) 'help-xref))
 
197
        (re-search-forward "\\s-")
 
198
        (setq fn (buffer-substring-no-properties beg (1- (point))))
 
199
        (if (equal type 'function)
 
200
            (ess-display-help-on-object fn)
 
201
          (ess-rpackage fn))))))
202
202
 
203
203
(defun ess-rpackage-mouse-view (event)
204
204
  "In rdired, visit the object on the line you click on."
207
207
  (let (window pos)
208
208
    (save-excursion
209
209
      (if (featurep 'xemacs)
210
 
          ;; XEmacs
211
 
          (setq window (event-window event)
212
 
                pos (event-point event))
213
 
        ;; Emacs
214
 
        (setq window (posn-window (event-end event))
215
 
              pos (posn-point (event-end event))))
 
210
          ;; XEmacs
 
211
          (setq window (event-window event)
 
212
                pos (event-point event))
 
213
        ;; Emacs
 
214
        (setq window (posn-window (event-end event))
 
215
              pos (posn-point (event-end event))))
216
216
      (if (not (windowp window))
217
 
          (error "No file chosen"))
 
217
          (error "No file chosen"))
218
218
      (set-buffer (window-buffer window))
219
219
      (goto-char pos)
220
220
      (ess-rpackage-show-help))))
238
238
      (search-forward "}")
239
239
      (delete-backward-char 1)
240
240
      (add-text-properties beg (point)
241
 
                           '(face underline
242
 
                                  mouse-face highlight
243
 
                                  help-xref library))
 
241
                           '(face underline
 
242
                                  mouse-face highlight
 
243
                                  help-xref library))
244
244
      (end-of-line)))
245
245
  (goto-char (point-min))
246
246
  )