Klimi's new dotfiles with stow.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

184 строки
6.6 KiB

4 лет назад
  1. ;;; ess-toolbar.el --- Support for a toolbar in ESS. -*- lexical-binding: t; -*-
  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: 2004-05-06
  6. ;; Revised: 2009-03-16
  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. ;; This code adds a toolbar to ESS modes for editing R and S code.
  21. ;; Support can be added for other modes (e.g. STATA), just ask!
  22. ;;
  23. ;; This code is experimental. It has been tested only on Linux
  24. ;; machines. All feedback appreciated.
  25. ;;
  26. ;; If your Emacs can support images, the ESS toolbar should be loaded.
  27. ;;
  28. ;; If you see a toolbar, but no icons, check out the value of
  29. ;; ess-icon-directory.
  30. ;;
  31. ;; The toolbar can be customized in several ways. To see options, do:
  32. ;; M-x customize-group RET ess-toolbar RET
  33. ;; If you change any of the variables, you _may_ need to restart Emacs
  34. ;; to see any effect. See also the documentation for ess-toolbar-items
  35. ;; if you wish to change its value.
  36. ;;; Technical issues.
  37. ;; 2009-03-16: toolbar code in Emacs 23 has changed slightly to 22,
  38. ;; and presumably once Emacs 22 is no longer supported, this code can
  39. ;; be cleaned up a bit (i.e. no need to set load-path.)
  40. ;;; Code:
  41. (require 'ess-mode)
  42. (defgroup ess-toolbar nil
  43. "ESS: toolbar support."
  44. :group 'ess
  45. :link '(emacs-commentary-link :tag "Commentary" "ess-toolbar.el")
  46. :prefix "ess-")
  47. (defcustom ess-use-toolbar
  48. (and (fboundp 'display-images-p) (display-images-p))
  49. "Non-nil means ESS should support the toolbar."
  50. :type 'boolean)
  51. (defcustom ess-toolbar-own-icons nil
  52. "Non-nil means that we only put our toolbar entries in ESS.
  53. Otherwise we get standard toolbar as well as ESS entries.
  54. The standard toolbar items are copied from the default toolbar."
  55. :type 'boolean)
  56. (defcustom ess-toolbar-global nil
  57. "*Non-nil means that the ESS toolbar is available in all Emacs buffers.
  58. Otherwise, the ESS toolbar is present only in R/S mode buffers.
  59. For beginners, this is probably better set to a non-nil value."
  60. :type 'boolean)
  61. (defcustom ess-toolbar-items
  62. '( (R "startr")
  63. ;;(S "spluslogo" "Start S process")
  64. (S "splus_letter_small")
  65. (ess-eval-line-and-step "rline")
  66. (ess-eval-region "rregion")
  67. (ess-eval-function-or-paragraph-and-step "rregion")
  68. (ess-load-file "rbuffer")
  69. (ess-eval-function "rfunction")
  70. (ess-switch-to-ESS "switch_ess"))
  71. "Items to be added to the ESS toolbar.
  72. Each list element has two items:
  73. 1. the name of the function to run
  74. 2. the icon to be used (without .xpm extension)
  75. General toolbar items are also added to the ESS toolbar
  76. iff `ess-toolbar-own-icons' is nil.
  77. Setting this variable with setq doesn't take effect once you have
  78. loaded ess-site, unless you follow it by a call to
  79. `ess-make-toolbar' afterwards. Instead, change its value using
  80. Custom, and then on all new ESS buffers you should see the
  81. toolbar has changed."
  82. :set (lambda (symbol value)
  83. (set-default symbol value)
  84. (if (fboundp 'ess-make-toolbar)
  85. (ess-make-toolbar)))
  86. :type '(repeat (list (function :tag "Function to run")
  87. (string :tag "Icon"))))
  88. (defvar ess-icon-directory
  89. (expand-file-name "icons" ess-etc-directory)
  90. "*Location for ESS icons.
  91. This variable should be set automatically by the ESS install process.
  92. Icons should be found in ESS/etc/icons/ directory.
  93. If `ess-icon-directory' is invalid, please report a bug.")
  94. (unless (file-directory-p ess-icon-directory)
  95. (ess-write-to-dribble-buffer
  96. "`ess-icon-directory' does not exist; using `ess-etc-directory'.\n")
  97. (setq ess-icon-directory ess-etc-directory))
  98. (defvar ess-toolbar nil
  99. "Toolbar items to be added to ESS editing buffers.")
  100. (defun ess-make-toolbar ()
  101. "Make the ESS toolbar."
  102. ;; Under Emacs, only worth building the toolbar if tool-bar-map is
  103. ;; available. e.g. when running Emacs within a terminal, tool-bar-map
  104. ;; is not available, so no need to make the tool-bar.
  105. (when (boundp 'tool-bar-map)
  106. (setq ess-toolbar
  107. (if (or ess-toolbar-own-icons (null tool-bar-map))
  108. (make-sparse-keymap)
  109. (copy-keymap tool-bar-map)))
  110. (let ((tool-bar-map ess-toolbar)
  111. (load-path (list ess-icon-directory)))
  112. ;; in Emacs 22, icons are found by examining load-path, bound here
  113. ;; whereas Emacs 23 seems to want them in image-load-path, set at the
  114. ;; bottom of this file.
  115. (mapc #'ess-add-icon ess-toolbar-items))))
  116. (defun ess-add-icon (x)
  117. "Add an ESS item to the Emacs toolbar.
  118. X should be a list, see `ess-toolbar-items' for the format."
  119. ;; By using tool-bar-add-item-from-menu instead of tool-bar-add-item
  120. ;; we get the tooltips "for free" from ess-mode-map.
  121. (tool-bar-add-item-from-menu (car x) (cadr x) ess-mode-map))
  122. (defun ess-add-toolbar ()
  123. "Add the ESS toolbar to a particular mode.
  124. The toolbar is added iff `ess-toolbar-global' is nil, else the toolbar
  125. is added globally when ess-toolbar.el is loaded."
  126. (when (and ess-toolbar (not ess-toolbar-global))
  127. (setq-local tool-bar-map ess-toolbar)))
  128. ;; Make the toolbars. Each toolbar is hopefully made only when this file
  129. ;; is loaded; we don't need it to be remade every time.
  130. (if ess-use-toolbar
  131. (progn
  132. (ess-make-toolbar)
  133. ;; After making the toolbar, if ESS toolbar is needed globally,
  134. ;; add it here.
  135. (if ess-toolbar-global
  136. (setq tool-bar-map ess-toolbar)
  137. (ess-write-to-dribble-buffer "Creating global Emacs toolbar"))
  138. ;; Check for toolbar support - needed iff ess-use-toolbar is non-nil.
  139. (or
  140. ;; Emacs support for images:
  141. (and (fboundp 'display-images-p) (display-images-p))
  142. ;; if above tests failed, give a warning.
  143. (progn
  144. (message "Toolbar support for ESS not available in this Emacs.")
  145. ;; Not sure if we want to delay startup of ESS.
  146. ;;(sit-for 2)
  147. ))
  148. ))
  149. ;; Following needed for Emacs 23, not Emacs 22
  150. (when (boundp 'image-load-path)
  151. (add-to-list 'image-load-path ess-icon-directory))
  152. (provide 'ess-toolbar)
  153. ;;; ess-toolbar.el ends here