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

« back to all changes in this revision

Viewing changes to lisp/ess-help.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:
52
52
(autoload 'ess-eval-line                "ess-inf" "[autoload]" t)
53
53
(autoload 'ess-eval-line-and-go         "ess-inf" "[autoload]" t)
54
54
(autoload 'ess-eval-line-and-step       "ess-inf" "[autoload]" t)
 
55
(autoload 'ess-with-current-buffer      "ess-inf" "[autoload]" t)
55
56
 
56
57
(autoload 'ess-goto-beginning-of-function-or-para    "ess-mode" "[autoload]" t)
57
58
(autoload 'ess-goto-end-of-function-or-para          "ess-mode" "[autoload]" t)
142
143
   (progn
143
144
     (ess-force-buffer-current)
144
145
     (when current-prefix-arg ;update cache if prefix
145
 
       (with-current-buffer (process-buffer (ess-get-process ess-current-process-name))
146
 
         (ess-process-put 'sp-for-help-changed? t)))
 
146
       (ess-process-put 'sp-for-help-changed? t))
147
147
     (if (ess-ddeclient-p)
148
148
         (list (read-string "Help on: "))
149
149
       (list (ess-find-help-file "Help on")))))
283
283
        )
284
284
    (cond
285
285
     ((string-match "^R" ess-dialect)
286
 
      (setq com-package-for-object "sub('package:', '', utils::find('%s'))\n"
 
286
      ;; carefully using syntax to be parsed in old R versions (no '::', '_'):
 
287
      (setq com-package-for-object "sub('package:', '', .ess.findFUN('%s'))\n"
287
288
            com-packages           ".packages(all.available=TRUE)\n"
288
 
            com-package-index      "help(package='%s', help_type='text')\n"
 
289
            com-package-index      ".ess.help(package='%s', help.type='text')\n"
289
290
            reg-keyword             "^\\([-a-zA-Z0-9._@$]+\\)[^:\n]*$"
290
291
            reg-start              "^Index:"))
291
292
     ((string-match "julia" ess-dialect)
547
548
                           (ess--find-displayed-help-window)))))
548
549
    (if help-win
549
550
        (progn
550
 
          (select-window help-win)
551
 
          (switch-to-buffer buff nil 'force))
 
551
          (select-window help-win 'norecord)
 
552
          (set-window-buffer help-win buff)
 
553
          ;; (switch-to-buffer buff nil 'force) <- 3rd argument appeared in emacs 24
 
554
          )
552
555
      (if ess-help-pop-to-buffer
553
556
          (pop-to-buffer buff)
554
557
        (ess-display-temp-buffer buff)))))
616
619
    (define-key ess-doc-map "r" 'ess-reference-lookup)
617
620
    ess-doc-map
618
621
    )
619
 
  "ESS documentaion map.")
 
622
  "ESS documentation map.")
620
623
 
621
624
 
622
625
(defvar ess-help-mode-map
674
677
;; One reason for the following menu is to <TEACH> the user about key strokes
675
678
(defvar ess-help-mode-menu
676
679
  (list "ESS-help"
677
 
        ["Search Forward"               isearch-forward t]
678
 
        ["Next Section"                 ess-skip-to-next-section t]
679
 
        ["Previous Section"             ess-skip-to-previous-section t]
680
 
        ["Help on Section Skipping"     ess-describe-sec-map t]
681
 
        ["Beginning of Buffer"          beginning-of-buffer t]
682
 
        ["End of Buffer"                end-of-buffer t]
683
 
        "-"
684
 
        ["Help on ..."                  ess-display-help-on-object t]
685
 
        ["Apropos of ..."               ess-display-help-apropos t]
686
 
        ["Index of ..."                 ess-display-package-index t]
687
 
        ["Vignettes"                    ess-display-vignettes t]
688
 
        ["Open in Browser"              ess-display-help-in-browser t]
689
 
        "-"
690
 
        ["Eval Line"                    ess-eval-line-and-step t]
691
 
        ["Eval Paragraph & step"        ess-eval-paragraph-and-step t]
692
 
        ["Eval Region & Go"             ess-eval-region-and-go t]
693
 
        ["Switch to ESS Process"        ess-switch-to-ESS t]
694
 
        ["Switch to End of ESS Proc."   ess-switch-to-end-of-ESS t]
695
 
        ["Switch _the_ Process"         ess-switch-process t]
696
 
        "-"
697
 
        ["Kill Buffer"                  kill-this-buffer t]
698
 
        ["Kill Buffer & Go"             ess-kill-buffer-and-go t]
699
 
        "-"
700
 
        ["Handy comomands"              ess-handy-commands t]
701
 
        ["Describe ESS-help Mode"       ess-describe-help-mode t]
 
680
        ["Search Forward"               isearch-forward t]
 
681
        ["Next Section"                 ess-skip-to-next-section t]
 
682
        ["Previous Section"             ess-skip-to-previous-section t]
 
683
        ["Help on Section Skipping"     ess-describe-sec-map t]
 
684
        ["Beginning of Buffer"          beginning-of-buffer t]
 
685
        ["End of Buffer"                end-of-buffer t]
 
686
        "-"
 
687
        ["Help on ..."                  ess-display-help-on-object t]
 
688
        ["Apropos of ..."               ess-display-help-apropos t]
 
689
        ["Index of ..."                 ess-display-package-index t]
 
690
        ["Vignettes"                    ess-display-vignettes t]
 
691
        ["Open in Browser"              ess-display-help-in-browser t]
 
692
        "-"
 
693
        ["Eval Line"                    ess-eval-line-and-step t]
 
694
        ["Eval Paragraph & step"        ess-eval-paragraph-and-step t]
 
695
        ["Eval Region & Go"             ess-eval-region-and-go t]
 
696
        ["Switch to ESS Process"        ess-switch-to-ESS t]
 
697
        ["Switch to End of ESS Proc."   ess-switch-to-end-of-ESS t]
 
698
        ["Switch _the_ Process"         ess-switch-process t]
 
699
        "-"
 
700
        ["Kill Buffer"                  kill-this-buffer t]
 
701
        ["Kill Buffer & Go"             ess-kill-buffer-and-go t]
 
702
        "-"
 
703
        ["Handy commands"               ess-handy-commands t]
 
704
        ["Describe ESS-help Mode"       ess-describe-help-mode t]
702
705
        )
703
706
  "Menu used in ess-help mode.")
704
707
 
760
763
                               ess-help-sec-keys-alist))))
761
764
      (if (not the-sec) (error "Invalid section key: %c"
762
765
                               last-command-event)
763
 
        (if (re-search-forward (concat "^" the-sec) nil t) nil
 
766
        (if (re-search-forward (concat "^" the-sec) nil t)
 
767
            (recenter)
764
768
          (message "No %s section in this help. Sorry." the-sec)
765
769
          (goto-char old-point))))))
766
770
 
882
886
 
883
887
(defun ess-get-help-aliases-list ()
884
888
  "Return a list of aliases which have help available."
885
 
  (let ((readrds (if (ess-current-R-at-least "2.13.0")
886
 
                     "readRDS"
887
 
                   ".readRDS")))
888
 
    (apply 'nconc
889
 
           (mapcar (lambda (str)
890
 
                     (let ((a-file (concat str "/help/aliases.rds")))
891
 
                       (and (file-exists-p a-file)
892
 
                            (ess-get-words-from-vector
893
 
                             (format "names(%s(\"%s\"))\n" readrds a-file)))))
894
 
                   (ess-get-words-from-vector "searchpaths()\n")))))
 
889
  (ess-write-to-dribble-buffer "Processing RDS files ...\n")
 
890
  (ess-get-words-from-vector ".ess.getHelpAliases()\n"))
895
891
 
896
892
(defun ess-nuke-help-bs ()
897
893
  "Remove ASCII underlining and overstriking performed by ^H codes."
949
945
 
950
946
(defun ess-describe-object-at-point ()
951
947
  "Get info for object at point, and display it in an electric buffer or tooltip.
952
 
This is an electric command (see `ess--execute-electric-command').
953
 
 
954
948
If region is active use it instead of the object at point.
955
949
 
956
 
After invocation of this command, all standard emacs commands,
 
950
This is an electric command (`ess--execute-electric-command'),
 
951
which means that you can use the last key to cycle through the
 
952
action set (in this case `C-e').
 
953
 
 
954
After invocation of this command all standard emacs commands,
957
955
except those containing 'window' in their names, remove the
958
956
electric *ess-describe* buffer. Use `other-window' to switch to
959
957
*ess-describe* window.
962
960
the description in a tooltip.
963
961
 
964
962
See also `ess-R-describe-object-at-point-commands' (and similar
965
 
option for other dialects).
966
 
"
 
963
option for other dialects)."
967
964
  (interactive)
968
965
  (if (not ess-describe-object-at-point-commands)
969
966
      (message "Not implemented for dialect %s" ess-dialect)
978
975
      ;; todo: put digits into the map
979
976
      (let* ((inhibit-quit t) ;; C-g removes the buffer
980
977
             (buf (ess--execute-electric-command
981
 
                   map (format "Press %s to cycle" (single-key-description last-command-event))
 
978
                   map (format "Press %s to cycle"
 
979
                               (single-key-description last-command-event))
982
980
                   nil nil objname))
983
981
             ;; read full command
984
982
             (keys (read-key-sequence-vector ""))
985
983
             (command (and keys (key-binding keys))))
986
984
        (when (and (commandp command)
987
985
                   (bufferp buf)
988
 
                   (not (string-match "window" (symbol-name command))))
 
986
                   (or (not (symbolp command)) ;; kill on lambdas
 
987
                       (not (string-match "window" (symbol-name command)))))
989
988
          (kill-buffer buf)) ;; bury does not work here :( (emacs bug?)
990
989
        (setq unread-command-events
991
990
              (append keys unread-command-events)))
1001
1000
      ;; can take some time for the command to execute
1002
1001
      (display-buffer buf))
1003
1002
    (sit-for .01)
1004
 
    (ess-command (concat com "\n") buf)
 
1003
    (ess-command (concat com "\n") buf) ;; erases buf
1005
1004
    (with-current-buffer buf
1006
1005
      (goto-char (point-min))
1007
1006
      (insert (propertize (format "%s:\n\n" com) 'face 'font-lock-string-face))
1008
1007
      (forward-line -1)
1009
1008
      (setq pos (point))
1010
 
      (setq buffer-read-only t))
 
1009
      ;; set the keys that we are used to in help mode
 
1010
      (special-mode)
 
1011
      (local-set-key "k" 'kill-this-buffer))
1011
1012
    (if (eq ess-describe-at-point-method 'tooltip)
1012
1013
        (ess-tooltip-show-at-point
1013
1014
         (with-current-buffer buf (buffer-string))  0 30)