Klimi's new dotfiles with stow.
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

219 řádky
8.4 KiB

před 4 roky
  1. ;;; ess-stata-mode.el --- Stata customization -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 1997--1999 A. J. Rossini, Thomas Lumley
  3. ;; Copyright (C) 1997--2004 A.J. Rossini, Richard M. Heiberger, Martin
  4. ;; Maechler, Kurt Hornik, Rodney Sparapani, and Stephen Eglen.
  5. ;; Author: A.J. Rossini <rossini@biostat.washington.edu>
  6. ;; Created: 9 Sep 1998
  7. ;; Maintainer: ESS-core <ESS-core@r-project.org>
  8. ;; Keywords: languages
  9. ;; This file is part of ESS
  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. ;; This file defines all the Stata customizations for ess-mode. It is somewhat
  22. ;; based on Stata-mode by Thomas Lumley <thomas@biostat.washington.edu>.
  23. ;;; Code:
  24. (require 'ess-mode)
  25. (require 'ess-stata-lang)
  26. (defvar STA-dialect-name "stata"
  27. "Name of 'dialect' for Stata.");easily changeable in a user's .emacs
  28. (defvar ess-stata-mode-syntax-table
  29. (let ((tbl (copy-syntax-table ess-mode-syntax-table)))
  30. (modify-syntax-entry ?\\ "." tbl) ;nullify escape meaning
  31. (modify-syntax-entry ?\$ "." tbl)
  32. (modify-syntax-entry ?` "(\'" tbl)
  33. (modify-syntax-entry ?\' ")`" tbl)
  34. (modify-syntax-entry ?/ ". 124b" tbl)
  35. ;; asterisk at bol comments taken care of by
  36. ;; `syntax-propertize-function'.
  37. (modify-syntax-entry ?* ". 23b" tbl)
  38. (modify-syntax-entry ?\n ">" tbl)
  39. (modify-syntax-entry ?+ "." tbl)
  40. (modify-syntax-entry ?- "." tbl)
  41. (modify-syntax-entry ?= "." tbl)
  42. (modify-syntax-entry ?% "." tbl)
  43. (modify-syntax-entry ?< "." tbl)
  44. (modify-syntax-entry ?> "." tbl)
  45. (modify-syntax-entry ?& "." tbl)
  46. (modify-syntax-entry ?| "." tbl)
  47. (modify-syntax-entry ?~ "." tbl)
  48. tbl)
  49. "Syntax table for `ess-stata-mode'.")
  50. (defvar STA-customize-alist
  51. '((ess-local-customize-alist . 'STA-customize-alist)
  52. (ess-language . "STA")
  53. (ess-dialect . STA-dialect-name)
  54. (ess-suffix . "ado")
  55. (ess-mode-editing-alist . STA-editing-alist)
  56. (ess-help-sec-regex . ess-help-STA-sec-regex)
  57. (ess-help-sec-keys-alist . ess-help-STA-sec-keys-alist)
  58. (ess-loop-timeout . 500000 )
  59. (ess-object-name-db-file . "ess-sta-namedb.el" )
  60. (inferior-ess-program . inferior-STA-program)
  61. (inferior-ess-objects-command . "describe\n")
  62. (inferior-ess-help-command . "help %s\n") ;; assumes set more off
  63. (inferior-ess-exit-command . "exit\n")
  64. ;; --more-- is necessary here (hangs otherwise if startup stata.msg is big)
  65. (inferior-ess-primary-prompt . "[.:] \\|--more--")
  66. (inferior-ess-secondary-prompt . ">\\|--more--")
  67. (inferior-ess-prompt . "\\([.:>] \\|--more--\\)")
  68. (comint-use-prompt-regexp . t)
  69. (inferior-ess-search-list-command . "set more off\n search()\n")
  70. (ess-execute-screen-options-command . "set linesize %s\n")
  71. (ess-getwd-command . "pwd\n")
  72. (ess-setwd-command . "cd \"%s\"\n")
  73. (ess-load-command . "run \"%s\"\n"))
  74. "Variables to customize for Stata.")
  75. (cl-defmethod ess--help-web-search-override (cmd &context (ess-dialect "stata"))
  76. "Browse the web for documentation about CMD in Stata."
  77. (browse-url
  78. (format
  79. "https://www.stata.com/search/?q=%s&restrict=&btnG=Search&client=stata&num=&output=xml_no_dtd&site=stata&ie=&oe=UTF-8&sort=&proxystylesheet=stata"
  80. cmd)))
  81. ;;;###autoload
  82. (define-derived-mode ess-stata-mode ess-mode "ESS[STA]"
  83. "Major mode for editing Stata source."
  84. :group 'ess-Stata
  85. (ess-setq-vars-local STA-customize-alist)
  86. (setq-local comint-use-prompt-regexp t)
  87. (setq-local comment-column 40)
  88. (setq-local comment-end " */")
  89. (setq-local comment-start "/* ")
  90. (setq-local comment-start-skip "/\\*+ *")
  91. (setq-local comment-use-syntax t)
  92. (setq-local syntax-propertize-function
  93. (syntax-propertize-rules ("^\\*" (0 "<"))))
  94. (setq-local paragraph-ignore-fill-prefix t)
  95. (setq-local paragraph-separate (concat "[ \t\f]*$\\|" page-delimiter))
  96. (setq-local paragraph-start (concat "[ \t\f]*$\\|" page-delimiter))
  97. (setq font-lock-defaults '(ess-STA-mode-font-lock-defaults nil nil ((?\. . "w")))))
  98. (defalias 'STA-mode 'ess-stata-mode)
  99. (defalias 'stata-mode 'ess-stata-mode)
  100. (defalias 'Stata-mode 'ess-stata-mode)
  101. ;;;###autoload
  102. (add-to-list 'auto-mode-alist '("\\.do\\'" . ess-stata-mode))
  103. ;;;###autoload
  104. (add-to-list 'auto-mode-alist '("\\.ado\\'" . ess-stata-mode))
  105. (defun ess-sta-remove-comments (string)
  106. "Remove one-line comments before sending the STRING to process.
  107. This function is placed in `ess-presend-filter-functions'."
  108. (replace-regexp-in-string "/\\*.*\\*/\\|^//.*$" "" string))
  109. ;; (ess-sta-remove-comments "aaa /* sdfdsf */ bbb
  110. ;; sdfsd
  111. ;; ccc
  112. ;; // sdfsf
  113. ;; sdf /* sdfdsf */
  114. ;; sdfsf
  115. ;; " )
  116. (defvar ess-stata-post-run-hook nil
  117. "Functions run in process buffer after the initialization of stata process.")
  118. (defun stata (&optional start-args)
  119. "Call Stata with START-ARGS."
  120. (interactive "P")
  121. (ess-write-to-dribble-buffer
  122. (format "(STA): ess-dialect=%s , buf=%s \n"
  123. ess-dialect
  124. (current-buffer)))
  125. (let* ((sta-start-args
  126. (concat inferior-STA-start-args
  127. (when start-args (read-string "Starting Args [possibly -k####] ? "))))
  128. (inf-buf (inferior-ess sta-start-args STA-customize-alist))
  129. (inf-proc (get-buffer-process inf-buf)))
  130. (while (process-get inf-proc 'sec-prompt)
  131. ;; get read of all --more-- if stata.msg is too long.
  132. (ess-send-string inf-proc "q")
  133. (ess-wait-for-process inf-proc t))
  134. (ess-send-string inf-proc "set more off")
  135. (goto-char (point-max))
  136. (with-current-buffer inf-buf
  137. (add-hook 'ess-presend-filter-functions 'ess-sta-remove-comments nil 'local)
  138. (run-mode-hooks 'ess-stata-post-run-hook))
  139. inf-buf))
  140. (defvar inferior-ess-stata-mode-syntax-table
  141. (let ((tab (copy-syntax-table ess-stata-mode-syntax-table)))
  142. tab)
  143. "Syntax table for `inferior-ess-stata-mode'.")
  144. (define-derived-mode inferior-ess-stata-mode inferior-ess-mode "iESS"
  145. "Inferior `stata' mode."
  146. :group 'ess-proc
  147. (ess-setq-vars-local STA-customize-alist)
  148. (setq comint-prompt-regexp (concat "^" inferior-ess-prompt))
  149. (setq-local comint-use-prompt-regexp t)
  150. (setq font-lock-defaults '(ess-STA-mode-font-lock-defaults nil nil ((?\. . "w")))))
  151. (define-derived-mode ess-stata-transcript-mode ess-transcript-mode "ESS Transcript"
  152. "Stata transcript mode."
  153. :group 'ess-Stata
  154. :syntax-table ess-stata-mode-syntax-table
  155. (ess-setq-vars-local STA-customize-alist)
  156. (setq comint-prompt-regexp (concat "^" inferior-ess-prompt))
  157. (setq-local comint-use-prompt-regexp t)
  158. (setq-local comment-column 40)
  159. (setq-local comment-end " */")
  160. (setq-local comment-start "/* ")
  161. (setq-local comment-start-skip "/\\*+ *")
  162. (setq-local comment-use-syntax t)
  163. (setq-local paragraph-ignore-fill-prefix t)
  164. (setq-local paragraph-separate (concat "[ \t\f]*$\\|" page-delimiter))
  165. (setq-local paragraph-start (concat "[ \t\f]*$\\|" page-delimiter))
  166. (setq font-lock-defaults '(ess-STA-mode-font-lock-defaults nil nil ((?\. . "w")))))
  167. (defalias 'STA-transcript-mode 'ess-stata-mode-syntax-table)
  168. (defun ess--STA-retrive-topics-from-search ()
  169. (with-current-buffer (ess-command inferior-ess-search-list-command)
  170. (goto-char (point-min))
  171. (let (topics)
  172. (while (re-search-forward "(help \\(.+?\\)\\( if installed\\| for replacement.*\\)?)$" nil t)
  173. (setq topics
  174. (nconc (split-string (match-string-no-properties 1) ",\\|; +")
  175. topics)))
  176. (nreverse (delete-dups topics))
  177. )))
  178. (cl-defmethod ess-help-get-topics (proc &context (ess-dialect "stata"))
  179. "Return a list of current STA help topics associated with process PROC."
  180. (or (ess-process-get 'help-topics proc)
  181. (progn
  182. (ess-process-put 'help-topics (ess--STA-retrive-topics-from-search))
  183. (ess-process-get 'help-topics))))
  184. (provide 'ess-stata-mode)
  185. ;;; ess-stata-mode.el ends here