Klimi's new dotfiles with stow.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

172 rader
6.0 KiB

4 år sedan
  1. ;;; ess-eldoc.el --- Use eldoc to report R function names.
  2. ;; Copyright (C) 1997--2009 A.J. Rossini, Richard M. Heiberger, Martin
  3. ;; Maechler, Kurt Hornik, Rodney Sparapani, and Stephen Eglen.
  4. ;; Author: Stephen Eglen
  5. ;; Created: 2007-06-30
  6. ;; Maintainer: ESS-core <ESS-core@r-project.org>
  7. ;; This file is part of ESS
  8. ;; This file is free software; you can redistribute it and/or modify
  9. ;; it under the terms of the GNU General Public License as published by
  10. ;; the Free Software Foundation; either version 2, or (at your option)
  11. ;; any later version.
  12. ;; This file is distributed in the hope that it will be useful,
  13. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;; GNU General Public License for more details.
  16. ;; A copy of the GNU General Public License is available at
  17. ;; http://www.r-project.org/Licenses/
  18. ;;; Commentary:
  19. ;;;;; eldoc funcitonality has been moved into the core ;;;;;
  20. ;;;;; this file has no effect and is left in ESS in order not to break
  21. ;;;;; users configuration
  22. ;; This is an initial attempt to use the emacs facility ELDOC in R
  23. ;; buffers. Eldoc is used in Emacs lisp buffers to show the function
  24. ;; arglist and docstrings for variables. To try it, view an emacs
  25. ;; lisp buffer, and then do M-x turn-on-eldoc-mode, and move over
  26. ;; function and variable names.
  27. ;; This file extends eldoc to work in R buffers. It currently uses
  28. ;; Sven's ess-r-args.el file to retrieve args for a given R function
  29. ;; (via ess-r-args-get). Note that it works slightly different to
  30. ;; Sven's code, in that you just need to have the point over the name
  31. ;; of an R function, or inside its arguments list, for eldoc to show
  32. ;; the arg list.
  33. ;; To use this functionality, simply add
  34. ;;
  35. ;; (require 'ess-eldoc)
  36. ;;
  37. ;; to your .emacs file. When you visit a R mode, eldoc will be turned
  38. ;; on. However, you will first need to associate the R buffer with an
  39. ;; *R* process so that args can be looked up -- otherwise, eldoc will
  40. ;; silently not report anything. So, e.g. try:
  41. ;; C-x C-f somefile.R
  42. ;; M-x R (so that somefile.R is associated with *R*)
  43. ;; eldoc should then work.
  44. ;; e.g. put the following rnorm() command in an R buffer. The line
  45. ;; underneath shows a key of what arg list will be shown as you move
  46. ;; across the rnorm line.
  47. ;; rnorm(n=100, mean=sqrt(20), sd=10)
  48. ;; 1111111111111222223333333311444111
  49. ;; 1: rnorm
  50. ;; 2: mean
  51. ;; 3: sqrt
  52. ;; 4: sd
  53. ;;
  54. ;; Note that the arg list for rnorm() should be shown either when you
  55. ;; are on the function name, or in the arg list. However, since the
  56. ;; 2nd and 3rd arguments are also function names, the arg lists of
  57. ;; those function names are reported instead. This might be seen as
  58. ;; undesirable behaviour, in which case a solution would be to only
  59. ;; look up the function name if it is followed by (.
  60. ;; If you want to use this feature in *R* buffers, add the following
  61. ;; to .emacs:
  62. ;; (add-hook 'inferior-ess-mode-hook 'ess-use-eldoc)
  63. ;; In the current version, I do not cache the arg list, but that was
  64. ;; done in an earlier version, to save repeated calls to
  65. ;; ess-r-args-get.
  66. ;; This code has been tested only in Emacs 22.1. It will not work on
  67. ;; Emacs 21, because it needs the variable
  68. ;; eldoc-documentation-function.
  69. ;;;; VS [25-02-2012]: all these issues were at least partially addresed in the
  70. ;;;; new implementation:
  71. ;; Bug (in eldoc?): the arg list for legend() is too long to fit in
  72. ;; minibuffer, and it seems that we see the last N lines of the arg
  73. ;; list, rather than the first N lines. It would be better to see the
  74. ;; first N lines since the more important args come first.
  75. ;; Doc issue: the eldoc vars (e.g. eldoc-echo-area-use-multiline-p)
  76. ;; work only for elisp mode.
  77. ;; Issue: You will probably see the message "Using process 'R'" flash;
  78. ;; this is generated by `ess-request-a-process', and I'd like to avoid
  79. ;; that appearing, non-interactively.
  80. ;; If *R* is currently busy (e.g. processing Sys.sleep(999)), then the
  81. ;; eldoc commands won't work; ess-command could be silenced in this
  82. ;; regard perhaps with a new SILENT arg for example to prevent the
  83. ;; call to (ess-error).
  84. ;;; Code:
  85. ;; ;; This could be done on buffer local basis.
  86. ;; (setq ess-r-args-noargsmsg "")
  87. ;; ;; following two defvars are not currently used.
  88. ;; (defvar ess-eldoc-last-name nil
  89. ;; "Name of the last function looked up in eldoc.
  90. ;; We remember this to see whether we need to look up documentation, or used
  91. ;; the cached value in `ess-eldoc-last-args'.")
  92. ;; (defvar ess-eldoc-last-args nil
  93. ;; "Args list last looked up for eldoc. Used as cache.")
  94. ;; (defun ess-eldoc-2 ()
  95. ;; ;; simple, old version.
  96. ;; (interactive)
  97. ;; (ess-r-args-get (ess-read-object-name-default)))
  98. ;; (defun ess-eldoc-1 ()
  99. ;; "Return the doc string, or nil.
  100. ;; This is the first version; works only on function name, not within arg list."
  101. ;; (interactive)
  102. ;; ;; Possible ways to get the function at point.
  103. ;; ;;(setq name (thing-at-point 'sexp))
  104. ;; ;;(setq name (ess-read-object-name-default))
  105. ;; ;;(setq name (find-tag-default))
  106. ;; (if ess-current-process-name
  107. ;; (progn
  108. ;; (setq name (ess-guess-fun)) ;guess the word at point.
  109. ;; (if (equal (length name) 0)
  110. ;; nil
  111. ;; ;; else
  112. ;; (unless (equal name ess-eldoc-last-name)
  113. ;; ;; name is different to the last name we lookedup, so get
  114. ;; ;; new args from R and store them.
  115. ;; (setq ess-eldoc-last-args (ess-r-args-get name)
  116. ;; ess-eldoc-last-name name))
  117. ;; ess-eldoc-last-args))
  118. ;; ;; no ESS process current.
  119. ;; nil)
  120. ;; )
  121. ;; (defsubst ess-guess-fun ()
  122. ;; "Guess what the function at point is."
  123. ;; ;; Derived from Man-default-man-entry in man.el
  124. ;; (let (word)
  125. ;; (save-excursion
  126. ;; (skip-chars-backward "-a-zA-Z0-9._+:")
  127. ;; (let ((start (point)))
  128. ;; (skip-chars-forward "-a-zA-Z0-9._+:")
  129. ;; (setq word (buffer-substring-no-properties start (point)))))
  130. ;; word))
  131. (defun ess-use-eldoc ()
  132. "Does nothing. Defined not to break old users' code."
  133. (interactive))
  134. (provide 'ess-eldoc)
  135. ;;; ess-eldoc.el ends here