Klimi's new dotfiles with stow.
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

534 satır
22 KiB

4 yıl önce
  1. ;;; ess-s-lang.el --- Support for editing S source code -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 1989-1997 D. Bates, Kademan, Ritter, D.M. Smith, K. Hornik,
  3. ;; R.M. Heiberger, M. Maechler, and A.J. Rossini.
  4. ;; Copyright (C) 1998-2015 A.J. Rossini, Richard M. Heiberger, Martin
  5. ;; Maechler, Kurt Hornik, Rodney Sparapani, and Stephen Eglen.
  6. ;; Author: A.J. Rossini <rossini@biostat.washington.edu>
  7. ;; Created: 26 Aug 1997
  8. ;; Maintainer: ESS-core <ESS-core@r-project.org>
  9. ;; This file is part of ESS (Emacs Speaks Statistics).
  10. ;; This file is free software; you can redistribute it and/or modify
  11. ;; it under the terms of the GNU General Public License as published by
  12. ;; the Free Software Foundation; either version 2, or (at your option)
  13. ;; any later version.
  14. ;; This file is distributed in the hope that it will be useful,
  15. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ;; GNU General Public License for more details.
  18. ;; A copy of the GNU General Public License is available at
  19. ;; https://www.r-project.org/Licenses/
  20. ;;; Commentary:
  21. ;; Code for general editing S source code (specializes to S, S+, R).
  22. ;;; Code:
  23. ; Requires and autoloads
  24. (require 'ess-mode)
  25. (require 'ess-help)
  26. (require 'ess-inf)
  27. (declare-function speedbar-add-supported-extension "speedbar" (extension))
  28. ; Configuration variables
  29. (defvar S-syntax-table
  30. (let ((S-syntax-table (make-syntax-table)))
  31. (modify-syntax-entry ?\\ "\\" S-syntax-table)
  32. (modify-syntax-entry ?+ "." S-syntax-table)
  33. (modify-syntax-entry ?- "." S-syntax-table)
  34. (modify-syntax-entry ?= "." S-syntax-table)
  35. (modify-syntax-entry ?% "." S-syntax-table)
  36. (modify-syntax-entry ?< "." S-syntax-table)
  37. (modify-syntax-entry ?> "." S-syntax-table)
  38. (modify-syntax-entry ?& "." S-syntax-table)
  39. (modify-syntax-entry ?| "." S-syntax-table)
  40. (modify-syntax-entry ?\' "\"" S-syntax-table)
  41. (modify-syntax-entry ?\" "\"" S-syntax-table)
  42. (modify-syntax-entry ?# "<" S-syntax-table) ; open comment
  43. (modify-syntax-entry ?\n ">" S-syntax-table) ; close comment
  44. ;;(modify-syntax-entry ?. "w" S-syntax-table) ; "." used in S obj names
  45. (modify-syntax-entry ?. "_" S-syntax-table) ; see above/below,
  46. ; plus consider separation.
  47. (modify-syntax-entry ?$ "_" S-syntax-table); foo$comp = 1 symbol(completion)
  48. (modify-syntax-entry ?@ "_" S-syntax-table); foo@slot = 1 symbol(completion)
  49. (modify-syntax-entry ?_ "_" S-syntax-table)
  50. (modify-syntax-entry ?: "_" S-syntax-table)
  51. (modify-syntax-entry ?* "." S-syntax-table)
  52. (modify-syntax-entry ?< "." S-syntax-table)
  53. (modify-syntax-entry ?> "." S-syntax-table)
  54. (modify-syntax-entry ?/ "." S-syntax-table)
  55. S-syntax-table)
  56. "Syntax table for S code."
  57. )
  58. (defvar S-editing-alist
  59. '((paragraph-start . (concat "\\s-*$\\|" page-delimiter))
  60. (paragraph-separate . (concat "\\s-*$\\|" page-delimiter))
  61. (paragraph-ignore-fill-prefix . t)
  62. ;;(comment-indent-function . 'S-comment-indent)
  63. ;;(ess-comment-indent . 'S-comment-indent)
  64. ;;(ess-calculate-indent . 'ess-calculate-indent)
  65. ;;(ess-keep-dump-files . 'ask)
  66. ;; For Changelog add, require ' ' before <- : "attr<-" is a function name :
  67. (add-log-current-defun-header-regexp . "^\\(.+\\)\\s-+<-[ \t\n]*function"))
  68. "General options for S and S+ source files.")
  69. (defvar inferior-S-language-start
  70. '(concat "options("
  71. "STERM='" ess-STERM "'"
  72. ", str.dendrogram.last=\"'\""
  73. (if ess-editor (concat ", editor='" ess-editor "'"))
  74. (if ess-pager (concat ", pager='" ess-pager "', help.pager='" ess-pager "'"))
  75. ", show.error.locations=TRUE"
  76. ")")
  77. "S language expression for startup -- default for all S dialects.")
  78. (defconst S-common-cust-alist
  79. '((ess-language . "S")
  80. (inferior-ess-exit-command . "q()\n")
  81. (inferior-ess-language-start . (eval inferior-S-language-start))
  82. (comint-use-prompt-regexp . t) ;;use fields if nil
  83. (comint-process-echoes . t)
  84. ;; these prompt are the same for all S-languages As long as custom prompt
  85. ;; ends in inferior-ess-primary-prompt everything should work as expected.
  86. (inferior-ess-primary-prompt . "> ")
  87. ;; (inferior-ess-secondary-prompt . "[+:] ") ;; catch Selection: and alike
  88. (inferior-ess-secondary-prompt . "+ ") ;; catch Selection: and alike
  89. (comment-start . "#")
  90. (comment-add . 1)
  91. (comment-start-skip . "#+ *")
  92. (comment-use-syntax . t) ; see log for bug report 2013-06-07
  93. (comment-column . 40)
  94. (ess-no-skip-regexp . (concat "^ *@\\|" (default-value 'ess-no-skip-regexp)))
  95. ;; inferior-ess-prompt is used by comint for navigation, only if
  96. ;; comint-use-prompt-regexp is t; (transcript-mode also relies on this regexp)
  97. (inferior-ess-prompt . inferior-S-prompt)
  98. (ess-getwd-command . "getwd()\n")
  99. (ess-setwd-command . "setwd('%s')\n")
  100. (ess-funargs-command . ".ess_funargs(\"%s\")\n")
  101. (fill-nobreak-predicate . 'ess-inside-string-p)
  102. (ess-execute-screen-options-command . "options(width=%d, length=99999)\n")
  103. (font-lock-defaults . '(ess-build-font-lock-keywords
  104. nil nil ((?\. . "w") (?\_ . "w")))))
  105. "S-language common settings for all <dialect>-customize-alist.")
  106. (defconst S+common-cust-alist
  107. (append
  108. '((ess-suffix . "S")
  109. (ess-help-sec-regex . ess-help-S+-sec-regex)
  110. (ess-help-sec-keys-alist . ess-help-S+sec-keys-alist)
  111. (ess-change-sp-regexp . ess-S+-change-sp-regexp)
  112. (ess-function-pattern . ess-s-function-pattern)
  113. (ess-function-template . " <- \n#\nfunction()\n{\n\n}\n")
  114. (ess-dump-filename-template . (replace-regexp-in-string
  115. "S$" ess-suffix ; in the one from custom:
  116. ess-dump-filename-template-proto))
  117. (ess-traceback-command . "traceback()\n")
  118. (ess-mode-editing-alist . S-editing-alist)
  119. (ess-dumped-missing-re
  120. . "\\(\\(<-\\|=\\)\nDumped\n\\'\\)\\|\\(\\(<-\\|=\\)\\(\\s \\|\n\\)*\\'\\)")
  121. (ess-syntax-error-re
  122. . "\\(Syntax error: .*\\) at line \\([0-9]*\\), file \\(.*\\)$")
  123. (inferior-ess-objects-command . inferior-Splus-objects-command)
  124. (ess-describe-object-at-point-commands . 'ess-S-describe-object-at-point-commands)
  125. (ess-editor . S-editor)
  126. (ess-pager . S-pager))
  127. S-common-cust-alist)
  128. "Common settings for all S+<*>-customize-alist."
  129. )
  130. ;;; Changes from S to S-PLUS 3.x. (standard S3 should be in ess-s-lang!).
  131. (defconst ess-help-S+sec-keys-alist
  132. '((?a . "ARGUMENTS:")
  133. (?b . "BACKGROUND:")
  134. (?B . "BUGS:")
  135. (?d . "DESCRIPTION:")
  136. (?D . "DETAILS:")
  137. (?e . "EXAMPLES:")
  138. (?n . "NOTE:")
  139. (?O . "OPTIONAL ARGUMENTS:")
  140. (?R . "REQUIRED ARGUMENTS:")
  141. (?r . "REFERENCES:")
  142. (?s . "SEE ALSO:")
  143. (?S . "SIDE EFFECTS:")
  144. (?u . "USAGE:")
  145. (?v . "VALUE:"))
  146. "Alist of (key . string) pairs for use in section searching.")
  147. ;;; `key' indicates the keystroke to use to search for the section heading
  148. ;;; `string' in an S help file. `string' is used as part of a
  149. ;;; regexp-search, and so specials should be quoted.
  150. ;; S ver.3 (NOT S-Plus)
  151. (defconst ess-help-S3-sec-keys-alist
  152. '((?a . "ARGUMENTS:")
  153. (?b . "BACKGROUND:")
  154. (?B . "BUGS:")
  155. (?d . "DESCRIPTION:")
  156. (?D . "DETAILS:")
  157. (?e . "EXAMPLES:")
  158. (?n . "NOTE:")
  159. (?r . "REFERENCES:")
  160. (?s . "SEE ALSO:")
  161. (?S . "SIDE EFFECTS:")
  162. (?u . "USAGE:")
  163. (?v . "VALUE:"))
  164. "Help section keys for S ver.3.")
  165. ;; S ver.4 (NOT S-Plus)
  166. (defconst ess-help-S4-sec-keys-alist
  167. '((?a . "ARGUMENTS:")
  168. (?b . "BACKGROUND:")
  169. (?B . "BUGS:")
  170. (?d . "DESCRIPTION:")
  171. (?D . "DETAILS:")
  172. (?e . "EXAMPLES:")
  173. (?n . "NOTE:")
  174. (?r . "REFERENCES:")
  175. (?s . "SEE ALSO:")
  176. (?S . "SIDE EFFECTS:")
  177. (?u . "USAGE:")
  178. (?v . "VALUE:"))
  179. "Help section keys for S4.")
  180. (defconst ess-help-S+-sec-regex "^[A-Z.]+:$"
  181. "Reg(ular) Ex(pression) of section headers in help file.")
  182. ; Function Definitions
  183. (defun S-comment-indent ()
  184. "Indentation for S comments."
  185. (if (or (looking-at "###")
  186. (and (looking-at "#!") (= 1 (line-number-at-pos))))
  187. (current-column)
  188. (if (looking-at "##")
  189. (let ((tem (when ;; FIXME ess-calculate-indent is R specific
  190. (fboundp 'ess-calculate-indent)
  191. (ess-calculate-indent))))
  192. (if (listp tem) (car tem) tem))
  193. (skip-chars-backward " \t")
  194. (max (if (bolp) 0 (1+ (current-column)))
  195. comment-column))))
  196. ;;*;; S/R Pretty-Editing
  197. (defun ess-fix-comments (&optional dont-query verbose)
  198. "Fix buffer so that single-line comments start with at least '##',
  199. and ensure space before subsequent text."
  200. (interactive "P")
  201. (ess-replace-regexp-dump-to-src "#\\([A-Za-z0-9]\\)" "# \\1" nil verbose)
  202. (ess-replace-regexp-dump-to-src "^\\([ \t]*#\\)\\([^#]\\)"
  203. "\\1#\\2" dont-query verbose))
  204. (defun ess-dump-to-src (&optional dont-query verbose)
  205. "Make the change in an S - dump() file to improve human readability.
  206. Optional arguments DONT-QUERY and VERBOSE are passed to
  207. `ess-replace-regexp-dump-to-src'."
  208. (interactive "P")
  209. (ess-replace-regexp-dump-to-src "^\"\\([a-z.][a-z.0-9]*\\)\" *<-\n"
  210. "\n\\1 <- "
  211. dont-query verbose))
  212. (defun ess-num-var-round (&optional dont-query verbose)
  213. "Round endings like 000000 and 99999.
  214. Optional argument DONT-QUERY means do not query.
  215. Optional argument VERBOSE gives more verbose output."
  216. (interactive "P")
  217. (save-excursion
  218. (goto-char (point-min))
  219. (let ((num 0)
  220. (str "")
  221. (rgxp "000000+[1-9]?[1-9]?\\>")
  222. (to ""))
  223. (if dont-query
  224. (ess-rep-regexp rgxp to nil nil verbose)
  225. (query-replace-regexp rgxp to nil))
  226. (while (< num 9)
  227. (setq str (concat (int-to-string num) "999999+[0-8]*"))
  228. (if (and (numberp verbose) (> verbose 1))
  229. (message (format "\nregexp: '%s'" str)))
  230. (goto-char (point-min))
  231. (ess-rep-regexp str (int-to-string (1+ num))
  232. 'fixedcase 'literal verbose)
  233. (setq num (1+ num))))))
  234. (defun ess-fix-dot (before-chars &optional dont-query verbose)
  235. "Remove trailing decimal '.' (\"dot\"), before BEFORE-CHARS.
  236. Optional argument DONT-QUERY and VERBOSE get passed to `ess-replace-regexp-dump-to-src'."
  237. ;; typically, before-chars = "]:" or more
  238. (ess-replace-regexp-dump-to-src
  239. (concat "\\([0-9]\\)\\.\\( *[" before-chars "]\\)")
  240. ;; 111 ^
  241. "\\1\\2" dont-query verbose))
  242. (defun ess-fix-dot-1 (&optional do-query verbose)
  243. "Remove trailing decimal '.' (\"dot\"), before ':' or ']', i.e.,
  244. in cases where it's ugly and nonsense. DO-QUERY(prefix) asks before replacing."
  245. (interactive "P")
  246. (ess-fix-dot "]:" (not do-query) verbose))
  247. (defun ess-fix-dot-more (&optional dont-query verbose)
  248. "Remove trailing decimal '.' (\"dot\", typically from S+) in more cases
  249. than `ess-fix-dot-1'."
  250. (interactive "P")
  251. (ess-fix-dot-1 nil verbose)
  252. (ess-fix-dot ",)" dont-query verbose))
  253. (defun ess-fix-EQ-assign (&optional dont-query verbose not-all)
  254. "Replace \"=\" by \"<-\" in places where it 'might make sense', e.g.,
  255. for function assignments and lines not ending in \",\".
  256. Be *careful* for list()s of functions and when argument not-all is
  257. nil (as by default) !"
  258. ;;TODO: "in the few places we can be very sure.."
  259. ;;---- is hard in general: local functions: ok; but functions in
  260. ;; list(a = function(x) abs(x), b= function(y) bound(y)) *NOT* ok!
  261. (interactive "P")
  262. (ess-replace-regexp-dump-to-src
  263. "^\\( *[a-z.][_a-z.0-9]*\\) *= *\\(function *(\\)"
  264. "\\1 <- \\2" dont-query verbose)
  265. (unless not-all
  266. ;; "too" aggressive {proposing to replace function argument specs}:
  267. (ess-replace-regexp-dump-to-src ;; all those *not* ending in ","
  268. ;; including Mat[ i, ] = ...,
  269. ;; but not `names(x) = "..."' for that is "confused" with plot(x=x,..)
  270. "^\\( *[a-z.][][, \"_a-z.0-9]*\\) *= *\\([a-z.0-9({]\\(.*[^,]\\)? *$\\)"
  271. "\\1 <- \\2" nil ;; always query - often has many "false positives"
  272. verbose)))
  273. ;;; All of the above three :
  274. (defun ess-MM-fix-src (&optional dont-query verbose)
  275. "Clean up ess-source code which has been produced by dump(..), and other
  276. code typically produced by other tools. Produces more readable code,
  277. and one that is well formatted in Emacs ess-mode."
  278. (interactive "P")
  279. ;; each of the following does a save-excursion:
  280. (ess-dump-to-src dont-query)
  281. (ess-fix-comments dont-query)
  282. (ess-num-var-round dont-query verbose)
  283. (ess-fix-dot-more dont-query verbose)
  284. (ess-fix-EQ-assign dont-query verbose 'not-all))
  285. (defun ess-fix-miscellaneous (&optional from verbose)
  286. "Fix Miscellaneous S/R `ill-formation's from current \\[point].
  287. Particularly use \"<-\"and put spaces around operators."
  288. (interactive "d\nP"); Defaults: point and prefix (C-u)
  289. ;; activate by (setq ess-verbose t)
  290. (ess-if-verbose-write
  291. (format "ess-fix-misc begin (from = %s, verbose = %s)\n" from verbose))
  292. (save-excursion
  293. (when (and (string= ess-dialect "R")
  294. (fboundp 'ess-r-fix-T-F))
  295. (ess-r-fix-T-F from (not verbose)))
  296. ;; activate by (setq ess-verbose t)
  297. (ess-if-verbose-write "ess-fix-misc: after fix-T-F\n");___D___
  298. ;; former C and matlab programmers leave trailing ";" :
  299. ;; (goto-char from) (ess-rep-regexp "; *$" "" nil 'literal verbose)
  300. ;; (ess-if-verbose-write "ess-fix-misc: after trailing ';'\n");___D___
  301. (goto-char from) (ess-rep-regexp ";\\( *\\)#" "\\1#" nil nil verbose)
  302. (ess-if-verbose-write "ess-fix-misc: after ';' before #\n");___D___
  303. ;;from R 1.9.x "_" is valid in names; here assume no initial / trailing '_'
  304. ;; BUG: The following changes "beta_ " or " _abc"
  305. ;; (goto-char from) (ess-rep-regexp " +_ *" " <- " nil 'literal verbose)
  306. ;; (goto-char from) (ess-rep-regexp "_ +" " <- " nil 'literal verbose)
  307. (ess-if-verbose-write "ess-fix-misc: before 'around \"<-\"' :\n");___D___
  308. ;; ensure space around "<-" ---- but only replace if necessary:
  309. (goto-char from)
  310. (ess-rep-regexp "\\([^< \t\n]\\)\\(<<?-\\)" "\\1 \\2" nil nil verbose)
  311. (goto-char from)(ess-rep-regexp "<-\\([^ \t\n]\\)" "<- \\1" nil nil verbose)
  312. ;; ensure space around "<" (not in "<-","<=","<<-") and ">" (not ">=") :
  313. (goto-char from);; --> " <", care with "->":
  314. (ess-rep-regexp "\\([^-< \t\n]\\)\\([<>]\\)" "\\1 \\2" nil nil verbose)
  315. ;; ">" -> "> " , for "<", don't split "<-" nor "<<-":
  316. (goto-char from)
  317. (ess-rep-regexp "\\(>=?\\)\\([^= \t\n]\\)" "\\1 \\2" nil nil verbose)
  318. (goto-char from)
  319. (ess-rep-regexp "\\(<=?\\)\\([^-<= \t\n]\\)" "\\1 \\2" nil nil t)
  320. (ess-if-verbose-write "ess-fix-misc: before \"=\" \"==\" .. :\n");___D___
  321. ;; -- ensure space around "=", "==", "!=" :
  322. (goto-char from) ;; --> " ="
  323. (ess-rep-regexp "\\([^=!<> ]\\)\\([=!]?\\)=" "\\1 \\2=" nil nil verbose)
  324. (goto-char from) (ess-rep-regexp "=\\([^= ]\\)" "= \\1" nil nil verbose)
  325. (goto-char from) ;; add a space between "{" and surrounding ..char:
  326. (ess-rep-regexp "{\\([.A-Za-z()]\\)" "{ \\1" 'fix nil verbose)
  327. (ess-rep-regexp "\\([()]\\){" "\\1 {" 'fix nil verbose)
  328. (goto-char from) ;; add a space between "}" and a preceding wordchar:
  329. (ess-rep-regexp "\\([A-Za-z0-9()]\\)}" "\\1 }" 'fix nil verbose)
  330. (ess-space-around "else" from verbose)
  331. (ess-if-verbose-write "ess-fix-misc: after \"{ ... }\" :\n");___D___
  332. (goto-char from) ;; add a space inside "){"
  333. (ess-rep-regexp "){" ") {" 'fix nil verbose)
  334. ;; add a newline and indent before a "}"
  335. ;; --- IFF there's NO "{" or "#" AND some NON-white text on the same line:
  336. ;;D (if verbose (message "\t R-fix-misc..: Hard.. '}'"))
  337. (goto-char from)
  338. (ess-rep-regexp "^\\([^#{\n]*[^#{ \t\n]+[ \t]*\\)}[ \t]*$"
  339. "\\1\n}" 'fix nil verbose)
  340. (ess-if-verbose-write "ess-fix-misc __end__\n");___D___
  341. ))
  342. (defun ess-cycle-assign ()
  343. "Cycle between assignment symbols in `ess-assign-list'.
  344. On consecutive calls, replace the assignment symbol before point
  345. with the next symbol from that list. This function sets the last
  346. keypress to repeat it, so if it is bound to \"C-c C-=\" pressing
  347. \"=\" again cycles to the next assignment."
  348. (interactive)
  349. (if (eq last-command this-command)
  350. (let ((slist ess-assign-list)
  351. str)
  352. ;; The or statements in the setq allow cycling past the end of
  353. ;; ess-assign-list.
  354. (while (and (setq str (or (car slist) (car ess-assign-list))
  355. slist (or (cdr slist) ess-assign-list))
  356. (not (and (re-search-backward str
  357. (- (point) (length str)) t)
  358. (not (replace-match (car slist))))))))
  359. (insert (car ess-assign-list)))
  360. (set-transient-map
  361. (let ((map (make-sparse-keymap))
  362. (key (format "%c" (event-basic-type last-input-event))))
  363. (define-key map (kbd key) #'ess-cycle-assign)
  364. map)))
  365. (defun ess-insert-assign (arg)
  366. "Insert the first element of `ess-assign-list' unless in string or comment.
  367. If the character before point is the first element of
  368. `ess-assign-list', replace it with the last character typed.
  369. If `ess-language' is not \"S\", call `self-insert-command' with ARG."
  370. (interactive "p")
  371. (if (string= ess-language "S")
  372. (let* ((assign (car ess-assign-list))
  373. (event (event-basic-type last-input-event))
  374. (char (ignore-errors (format "%c" event))))
  375. (cond ((and char (ess-inside-string-or-comment-p))
  376. (insert char))
  377. ((re-search-backward assign (- (point) (length assign)) t)
  378. (if (and char (numberp event))
  379. (replace-match char t t)
  380. (replace-match "")))
  381. (t (insert assign))))
  382. (funcall #'self-insert-command arg)))
  383. ;; In case people had this in their config don't cause errors:
  384. (define-obsolete-function-alias 'ess-smart-S-assign 'ess-insert-assign "ESS 18.10")
  385. (define-obsolete-function-alias 'ess-disable-smart-S-assign #'ignore "ESS 18.10")
  386. (defun ess-add-MM-keys ()
  387. "Define MM's user keys."
  388. (declare (obsolete "Setup your own keybindings." "ESS 19.04"))
  389. (define-key inferior-ess-mode-map "\C-cw" #'ess-execute-screen-options)
  390. (define-key ess-mode-map [?\M--] #'ess-insert-assign)
  391. (define-key inferior-ess-mode-map [?\M--] #'ess-insert-assign))
  392. (defun ess-dump-args-and-go (Sfunc)
  393. "Dump the function name, with arguments, to a buffer for editing.
  394. Currently, this needs to:
  395. 1. set the buffer to the right mode, with the right settings
  396. 2. format the statement,
  397. 3. c/function/Sfunc/
  398. and I need to relearn Emacs lisp (but I had to, anyway."
  399. (interactive "sFunction ? ")
  400. (declare (obsolete 'ess-execute "ESS 19.04"))
  401. (let* ((buffname "ess-complete.R"))
  402. (ess-execute (format "args(%s)" Sfunc) t buffname)
  403. (pop-to-buffer (concat "*" buffname "*"))
  404. (while (search-forward "function" nil t)
  405. (replace-match Sfunc nil t))
  406. (when (fboundp 'ess-r-mode)
  407. (ess-r-mode))))
  408. ;;; S imenu support
  409. ;; don't use syntax classes, bad for etags
  410. (defvar ess-imenu-S-generic-expression
  411. '(("Functions" "^\\([^ \t\n]+\\)[ \t\n]*\\(?:<-\\|=\\)[ \t\n]*function[ ]*(" 1)
  412. ("Classes" "^.*setClass(\\(.*\\)," 1)
  413. ("Coercions" "^.*setAs(\\([^,]+,[^,]*\\)," 1) ; show from and to
  414. ("Generics" "^.*setGeneric(\\([^,]*\\)," 1)
  415. ("Methods" "^.*set\\(Group\\|Replace\\)?Method(\\([^,]+,[^,]*\\)" 2)
  416. ("Package" "^.*\\(library\\|require\\)(\\([^)]*\\)" 2)
  417. ("Data" "^\\(.+\\)[ \t\n]-*\\(?:<-\\|=\\)[ \t\n]*\\(read\\|.*data\\.frame\\).*(" 1))
  418. "Imenu generic expression for S modes.
  419. See `imenu-generic-expression'.")
  420. (defun ess-imenu-S (&optional _arg)
  421. "S Language Imenu support for ESS.
  422. ARG is ignored."
  423. (declare (obsolete "It is set automatically in major modes" "ESS 19.04"))
  424. (imenu-add-to-menubar "Imenu-S"))
  425. (define-obsolete-function-alias 'ess-imenu-R 'ess-imenu-S "ESS 19.04")
  426. ;;; Speedbar stuff.
  427. (eval-after-load "speedbar"
  428. '(progn
  429. (speedbar-add-supported-extension ".R")
  430. (speedbar-add-supported-extension ".S")
  431. (speedbar-add-supported-extension ".s")
  432. (speedbar-add-supported-extension ".q")))
  433. (cl-defmethod ess-help-get-topics (proc &context (ess-dialect "R"))
  434. "Return a list of current S help topics associated with process PROC.
  435. If 'sp-for-help-changed?' process variable is non-nil or
  436. `ess-help-topics-list' is nil, (re)-populate the latter and
  437. return it. Otherwise, return `ess-help-topics-list'."
  438. (with-ess-process-buffer nil
  439. (cond
  440. ;; (Re)generate the list of topics
  441. ((or (not ess-help-topics-list)
  442. (ess-process-get 'sp-for-help-changed?))
  443. (ess-process-put 'sp-for-help-changed? nil)
  444. (setq ess-help-topics-list
  445. (delete-dups
  446. (append (ess-get-object-list proc 'exclude-1st)
  447. (ess-get-help-files-list)
  448. (ess-get-help-aliases-list)))))
  449. (t
  450. ess-help-topics-list))))
  451. (defalias 'S 'S+)
  452. (defalias 's-mode 'S+-mode)
  453. (defalias 's-transcript-mode 'S+-transcript-mode)
  454. (defalias 'S-transcript-mode 's-transcript-mode)
  455. (defalias 'S-mode 's-mode)
  456. (define-obsolete-function-alias 'ess-toggle-S-assign-key #'ignore "ESS 18.10")
  457. (define-obsolete-function-alias 'ess-smart-underscore 'ess-insert-assign "ESS 18.10")
  458. (define-obsolete-function-alias 'ess-insert-S-assign 'ess-insert-assign "ESS 18.10")
  459. (define-obsolete-function-alias 'ess-toggle-underscore 'ess-disable-smart-S-assign "ESS 18.10")
  460. (define-obsolete-function-alias 'ess-toggle-S-assign 'ess-disable-smart-S-assign "ESS 18.10")
  461. ;;;###autoload
  462. (add-to-list 'auto-mode-alist '("\\.[Ss]t\\'" . S-transcript-mode))
  463. ;;;###autoload
  464. (add-to-list 'auto-mode-alist '("\\.Sout" . S-transcript-mode))
  465. (provide 'ess-s-lang)
  466. ;;; ess-s-lang.el ends here