Klimi's new dotfiles with stow.
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

222 linhas
8.7 KiB

há 4 anos
  1. ;;; ess-mouse.el --- Support for mouse- or cursor-sensitive actions
  2. ;; Copyright (C) 2001 Richard M. Heiberger <rmh@temple.edu>
  3. ;; Copyright (C) 2002--2004 A.J. Rossini, Richard M. Heiberger, Martin
  4. ;; Maechler, Kurt Hornik, Rodney Sparapani, and Stephen Eglen.
  5. ;; Author: Richard M. Heiberger <rmh@temple.edu>
  6. ;; Created: 25 Mar 2001
  7. ;; Maintainer: ESS-core <ESS-core@r-project.org>
  8. ;; This file is part of ESS
  9. ;; This file is free software; you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation; either version 2, or (at your option)
  12. ;; any later version.
  13. ;; This file is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;; A copy of the GNU General Public License is available at
  18. ;; https://www.r-project.org/Licenses/
  19. ;;; Commentary:
  20. ;; Support for mouse- or cursor-sensitive actions. This is based on
  21. ;; and uses mouseme.el. mouseme.el only does mouse sensititivity.
  22. ;; The new functions ess-mouse-me and ess-mouse-me-helper do similar
  23. ;; things based on the cursor, not the mouse, and can be bound to a
  24. ;; keystroke.
  25. ;;; Code:
  26. ; Requires and autoloads
  27. ;;*;; Requires
  28. (require 'mouseme)
  29. (require 'ess-trns)
  30. ;;(if (or (equal window-system 'w32)
  31. ;; (equal window-system 'win32)
  32. ;; (equal window-system 'mswindows))
  33. ;; (require 'essiw32b))
  34. (defun ess-mouse-me ()
  35. "Popup a menu of functions to run on selected string or region."
  36. (interactive)
  37. (ess-mouse-me-helper
  38. (lambda (name)
  39. (or (x-popup-menu (list '(0 0)
  40. (get-buffer-window (get-buffer (buffer-name))))
  41. (funcall mouse-me-build-menu-function name))
  42. (error "No command to run")))))
  43. (defun ess-mouse-me-helper (func)
  44. "Determine the string to use to process EVENT and call FUNC to get cmd."
  45. (let (name sp sm mouse beg end cmd mmtype)
  46. ;; temporarily goto where the event occurred, get the name clicked
  47. ;; on and enough info to figure out what to do with it
  48. (save-match-data
  49. (save-excursion
  50. (setq sp (point)) ; saved point
  51. (setq sm (mark t)) ; saved mark
  52. ;;; (set-buffer (window-buffer (posn-window (event-start event))))
  53. ;;; (setq mouse (goto-char (posn-point (event-start event))))
  54. (setq mouse (point)) ;; ess-mouse-me-helper
  55. ;; if there is a region and point is inside it
  56. ;; check for sm first incase (null (mark t))
  57. ;; set name to either the thing they clicked on or region
  58. (if (and sm
  59. (or (and transient-mark-mode mark-active)
  60. (eq last-command 'mouse-drag-region))
  61. (>= mouse (setq beg (min sp sm)))
  62. (<= mouse (setq end (max sp sm))))
  63. (setq name (buffer-substring beg end))
  64. (setq name (funcall mouse-me-get-string-function))
  65. (if (listp name)
  66. (setq beg (nth 1 name)
  67. end (nth 2 name)
  68. name (car name))
  69. (goto-char mouse)
  70. (while (not (looking-at (regexp-quote name)))
  71. (backward-char 1))
  72. (setq beg (point))
  73. (setq end (search-forward name))))))
  74. ;; check if name is null, meaning they clicked on no word
  75. (if (or (null name)
  76. (and (stringp name) (string= name "" )))
  77. (error "No string to pass to function"))
  78. ;; popup a menu to get a command to run
  79. (setq cmd (funcall func name))
  80. ;; run the command, eval'ing if it was a list
  81. (if (listp cmd)
  82. (setq cmd (eval cmd)))
  83. (setq mmtype (get cmd 'mouse-me-type))
  84. (cond ((eq mmtype 'region)
  85. (funcall cmd beg end))
  86. ((eq mmtype 'string)
  87. (funcall cmd name))
  88. (t
  89. (funcall cmd name)))))
  90. (defcustom ess-S-mouse-me-menu-commands-alist
  91. '("S-Plus 4 and 6 GUI under Windows"
  92. ("Edit.data" . ess-mouse-me-Edit.data)
  93. "----"
  94. ("print" . ess-mouse-me-print)
  95. ("summary" . ess-mouse-me-summary)
  96. ("plot" . ess-mouse-me-plot)
  97. ("show" . ess-mouse-me-show)
  98. ("help" . ess-display-help-on-object)
  99. ("args" . ess-mouse-me-args)
  100. "----"
  101. ("Browser on" . ess-mouse-me-browser-on)
  102. ("Browser off" . ess-mouse-me-browser-off))
  103. "Command menu used by `mouse-me-build-menu'.
  104. A alist of elements where each element is either a cons cell or a string.
  105. If a cons cell the car is a string to be displayed in the menu and the
  106. cdr is either a function to call passing a string to, or a list which evals
  107. to a function to call passing a string to. If the element is a string
  108. it makes a non-selectable element in the menu. To make a separator line
  109. use a string consisting solely of hyphens.
  110. The function returned from this menu will be called with one string
  111. argument. Or if the function has the symbol property `mouse-me-type'
  112. and if its value is the symbol `region' it will be called with the
  113. beginning and ending points of the selected string. If the value is
  114. the symbol `string' it will be called with one string argument."
  115. :type '(repeat sexp)
  116. :group 'mouseme)
  117. (defun ess-mouse-me-Edit.data (string)
  118. (ess-mouse-me-eval-expanded string "Edit.data(" ")" nil nil nil))
  119. (defun ess-mouse-me-print (string)
  120. (ess-mouse-me-eval-expanded string "" "" nil nil t))
  121. (defun ess-mouse-me-summary (string)
  122. (ess-mouse-me-eval-expanded string "summary(" ")" nil nil t))
  123. (defun ess-mouse-me-plot (string)
  124. (ess-mouse-me-eval-expanded string "plot(" ")") nil nil nil)
  125. (defun ess-mouse-me-show (string)
  126. (ess-mouse-me-eval-expanded string "show(" ")") nil nil nil)
  127. (defun ess-mouse-me-args (string)
  128. (ess-mouse-me-eval-expanded string "args(" ")" nil nil t))
  129. (defun ess-mouse-me-browser-on (string)
  130. (if (equal (substring ess-dialect 0 1) "R")
  131. (ess-eval-linewise (concat "debug(" string ")"))
  132. (ess-mouse-me-eval-expanded string "trace(" ", exit=browser)") nil nil nil))
  133. (defun ess-mouse-me-browser-off (string)
  134. (if (equal (substring ess-dialect 0 1) "R")
  135. (ess-eval-linewise (concat "undebug(" string ")"))
  136. (ess-mouse-me-eval-expanded string "untrace(" ")") nil nil nil))
  137. (defun ess-mouse-me-eval-expanded (string &optional head tail commands-buffer
  138. page value-returned)
  139. "Send the expanded STRING to the inferior-ess process using `ess-command'
  140. after first concating the HEAD and TAIL. Put answer in COMMANDS-BUFFER if
  141. specified, otherwise in \"tmp-buffer\". In either
  142. case the buffer containing the answer is renamed to the value of the
  143. constructed command. If PAGE is non-nil, expand
  144. the string one more time by embedding it in a \"page()\" command."
  145. (interactive)
  146. (let* (scommand
  147. page-scommand
  148. (lproc-name ess-local-process-name)
  149. (ess-mouse-customize-alist ess-local-customize-alist))
  150. (if (not head) (setq head "summary("))
  151. (if (not tail) (setq tail ")"))
  152. (if (not commands-buffer) (setq commands-buffer
  153. (get-buffer-create "tmp-buffer")))
  154. (setq scommand (concat head string tail))
  155. (ess-make-buffer-current)
  156. (pop-to-buffer-same-window commands-buffer)
  157. (ess-setq-vars-local (eval ess-mouse-customize-alist) (current-buffer))
  158. (setq ess-local-process-name lproc-name)
  159. (ess-command (concat scommand "\n") commands-buffer)
  160. (if (not value-returned) (pop-to-buffer-same-window (nth 1 (buffer-list))))
  161. (if (not value-returned)
  162. nil
  163. (if ess-microsoft-p ;; there ought to be a filter
  164. (while (search-forward "\r" nil t) ;; function to keep the ^M
  165. (replace-match "" nil t))) ;; from showing up at all
  166. (ess-transcript-mode)
  167. (setq ess-local-process-name lproc-name)
  168. (rename-buffer scommand))))
  169. ; Provide package
  170. (provide 'ess-mouse)
  171. ;;;;;;;; STARTUP STUFF ;;;;;;;;;;;;
  172. (make-variable-buffer-local 'mouse-me-menu-commands)
  173. (defun ess-S-mouse-me-menu-commands ()
  174. (if (equal ess-language "S")
  175. (setq mouse-me-menu-commands ess-S-mouse-me-menu-commands-alist)))
  176. ;; (define-key ess-mode-map [S-mouse-3] 'ess-mouse-me)
  177. ;; (define-key inferior-ess-mode-map [S-mouse-3] 'ess-mouse-me)
  178. ;; (defun ess-S-mouse-me-ess-transcript-mode ()
  179. ;; (define-key ess-transcript-mode-map [S-mouse-3] 'ess-mouse-me))
  180. ;;
  181. (add-hook 'ess-mode-hook 'ess-S-mouse-me-menu-commands)
  182. (add-hook 'inferior-ess-mode-hook 'ess-S-mouse-me-menu-commands)
  183. (add-hook 'ess-transcript-mode-hook 'ess-S-mouse-me-menu-commands)
  184. ;; (add-hook 'ess-transcript-mode-hook 'ess-S-mouse-me-ess-transcript-mode)
  185. ;;; ess-mouse.el ends here