/usr/share/emacs/site-lisp/ess/ess-trns.el is in ess 5.14-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 | ;;; ess-trns.el --- Support for manipulating S transcript files
;; Copyright (C) 1989--1994 Bates, Kademan, Ritter and Smith
;; Copyright (C) 1997--2005 A.J. Rossini, Rich M. Heiberger, Martin
;; Maechler, Kurt Hornik, Rodney Sparapani, and Stephen Eglen.
;; Original Author: David Smith <dsmith@stats.adelaide.edu.au>
;; Maintainers: ESS-core <ESS-core@r-project.org>
;; This file is part of ESS
;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to
;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
;;; Commentary:
;; Code for dealing with ESS transcripts.
;;; Code:
; Requires and autoloads
(require 'ess)
(eval-when-compile
(require 'comint)
(require 'ess-inf))
(autoload 'ess-eval-region "ess-inf" "[autoload]" t)
(autoload 'ess-eval-region-and-go "ess-inf" "[autoload]" t)
(autoload 'ess-eval-function "ess-inf" "[autoload]" t)
(autoload 'ess-eval-function-and-go "ess-inf" "[autoload]" t)
(autoload 'ess-eval-line "ess-inf" "[autoload]" t)
(autoload 'ess-eval-line-and-go "ess-inf" "[autoload]" t)
(autoload 'ess-eval-line-and-step "ess-inf" "[autoload]" t)
(autoload 'comint-previous-prompt "comint" "[autoload]" t)
(autoload 'comint-next-prompt "comint" "[autoload]" t)
(autoload 'ess-load-file "ess-inf" "[autoload]" t)
(autoload 'ess-request-a-process "ess-inf" "(autoload)" nil)
(autoload 'get-ess-buffer "ess-inf" "(autoload)" nil)
(autoload 'ess-switch-to-ESS "ess-inf" "(autoload)" nil)
(autoload 'ess-switch-to-end-of-ESS "ess-inf" "(autoload)" nil)
(autoload 'ess-eval-linewise "ess-inf" "(autoload)" nil)
(autoload 'inferior-ess-get-old-input "ess-inf" "(autoload)" nil)
; ess-transcript-mode
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; In this section:
;;;;
;;;; * The major mode ess-transcript-mode
;;;; * Commands for ess-transcript-mode
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;*;; Major mode definition
(defvar ess-transcript-mode-map nil "Keymap for `ess-transcript-mode'.")
(if ess-transcript-mode-map
nil
(cond ((featurep 'xemacs)
;; Code for XEmacs
(setq ess-transcript-mode-map (make-keymap))
(set-keymap-parent ess-transcript-mode-map text-mode-map))
((not (featurep 'xemacs))
;; Code for GNU Emacs
(setq ess-transcript-mode-map (make-sparse-keymap))))
(define-key ess-transcript-mode-map "\C-c\C-s" 'ess-switch-process)
(define-key ess-transcript-mode-map "\C-c\C-r" 'ess-eval-region)
(define-key ess-transcript-mode-map "\C-c\M-r" 'ess-eval-region-and-go)
;; (define-key ess-transcript-mode-map "\M-\C-x" 'ess-eval-function)
;; (define-key ess-transcript-mode-map "\C-c\M-f" 'ess-eval-function-and-go)
;; (define-key ess-transcript-mode-map "\C-c\C-j" 'ess-eval-line)
;; (define-key ess-transcript-mode-map "\C-c\M-j" 'ess-eval-line-and-go)
(define-key ess-transcript-mode-map "\C-c\C-k" 'ess-force-buffer-current)
(define-key ess-transcript-mode-map "\C-c\C-q" 'ess-quit)
(define-key ess-transcript-mode-map "\C-c\C-j" 'ess-transcript-send-command)
(define-key ess-transcript-mode-map "\C-c\M-j" 'ess-transcript-send-command-and-move)
(define-key ess-transcript-mode-map "\M-\C-a" 'ess-beginning-of-function)
(define-key ess-transcript-mode-map "\M-\C-e" 'ess-end-of-function)
(define-key ess-transcript-mode-map "\C-c\C-y" 'ess-switch-to-ESS)
(define-key ess-transcript-mode-map "\C-c\C-z" 'ess-switch-to-end-of-ESS)
(define-key ess-transcript-mode-map "\C-c\C-v" 'ess-display-help-on-object)
(define-key ess-transcript-mode-map "\C-c\C-d" 'ess-dump-object-into-edit-buffer)
(define-key ess-transcript-mode-map "\C-c\C-t" 'ess-execute-in-tb)
(define-key ess-transcript-mode-map "\C-c\t" 'ess-complete-object-name)
(define-key ess-transcript-mode-map "\C-a" 'comint-bol)
(define-key ess-transcript-mode-map "\M-\t" 'comint-replace-by-expanded-filename)
(define-key ess-transcript-mode-map "\M-?" 'comint-dynamic-list-completions)
(define-key ess-transcript-mode-map "\C-c\C-k" 'ess-request-a-process)
(define-key ess-transcript-mode-map "{" 'ess-electric-brace)
(define-key ess-transcript-mode-map "}" 'ess-electric-brace)
(define-key ess-transcript-mode-map "\e\C-h" 'ess-mark-function)
(define-key ess-transcript-mode-map "\e\C-q" 'ess-indent-exp)
;(define-key ess-transcript-mode-map "\177" 'backward-delete-char-untabify)
(define-key ess-transcript-mode-map "\t" 'ess-indent-command)
(define-key ess-transcript-mode-map "\C-c\C-p" 'comint-previous-prompt)
(define-key ess-transcript-mode-map "\C-c\C-n" 'comint-next-prompt)
;; (define-key ess-transcript-mode-map "\C-c\C-n" 'ess-eval-line-and-step)
(define-key ess-transcript-mode-map "\r" 'ess-transcript-send-command-and-move)
(define-key ess-transcript-mode-map "\M-\r" 'ess-transcript-send-command)
(define-key ess-transcript-mode-map "\C-c\r" 'ess-transcript-copy-command)
(define-key ess-transcript-mode-map "\C-c\C-w" 'ess-transcript-clean-region))
(easy-menu-define
ess-transcript-mode-menu ess-transcript-mode-map
"Menu for use in S transcript mode."
'("ESS-trans"
["What is this? (beta)" ess-mouse-me t]
["Describe" describe-mode t]
["About" (ess-goto-info "Transcript Mode") t]
["Send bug report" ess-submit-bug-report t]
"------"
["Mark cmd group" mark-paragraph t]
["Previous prompt" comint-previous-prompt t]
["Next prompt" comint-next-prompt t]
"------"
["Send and move" ess-transcript-send-command-and-move t]
["Copy command" ess-transcript-copy-command t]
["Send command" ess-transcript-send-command t]
["Clean Region" ess-transcript-DO-clean-region t]
["Switch S process" ess-switch-process t]
))
(unless (featurep 'xemacs)
(if (featurep 'ess-trans)
(define-key ess-transcript-mode-map [menu-bar ess-trans]
(cons "ess-trans" ess-transcript-mode-menu))
(eval-after-load "ess-trans"
'(define-key ess-transcript-mode-map
[menu-bar ess-trans]
(cons "ess-trans"
ess-transcript-mode-menu)))))
(when (featurep 'xemacs)
(defun ess-transcript-mode-xemacs-menu ()
"Hook to install `ess-transcript-mode' menu for XEmacs (w/ easymenu)."
(if 'ess-transcript-mode
(easy-menu-add ess-transcript-mode-menu)
(easy-menu-remove ess-transcript-mode-menu)))
(add-hook 'ess-transcript-mode-hook 'ess-transcript-mode-xemacs-menu))
(defun ess-transcript-mode (alist &optional proc)
"Major mode for manipulating {ESS} transcript files.
Type \\[ess-transcript-send-command] to send a command in the
transcript to the current S process. \\[ess-transcript-copy-command]
copies the command but does not execute it, allowing you to edit it in
the process buffer first.
Type \\[ess-transcript-clean-region] to delete all outputs and prompts
in the region, leaving only the S commands. Other keybindings are:
\\{ess-transcript-mode-map}"
(interactive)
(require 'ess-inf)
(kill-all-local-variables)
(toggle-read-only t) ;; to protect the buffer.
(ess-setq-vars-local alist); (current-buffer))
(setq major-mode 'ess-transcript-mode)
(setq mode-name "ESS Transcript")
(use-local-map ess-transcript-mode-map)
(set-syntax-table ess-mode-syntax-table)
(setq mode-line-process
'(" [" ess-local-process-name "]"))
(make-local-variable 'ess-local-process-name)
(setq ess-local-process-name nil)
(make-local-variable 'paragraph-start)
(setq paragraph-start (concat "^" inferior-ess-primary-prompt "\\|^\^L"))
(make-local-variable 'paragraph-separate)
(setq paragraph-separate "^\^L")
(setq inferior-ess-prompt
;; Do not anchor to bol with `^' ; (copied from ess-inf.el)
(concat "\\("
inferior-ess-primary-prompt
"\\|"
inferior-ess-secondary-prompt
"\\)"))
(make-local-variable 'comint-prompt-regexp)
(setq comint-prompt-regexp (concat "^" inferior-ess-prompt))
;; font-lock support
(make-local-variable 'font-lock-defaults)
(setq font-lock-defaults
'(inferior-ess-font-lock-keywords nil nil ((?' . "."))))
;;; Keep <tabs> out of the code.
(make-local-variable 'indent-tabs-mode)
(setq indent-tabs-mode nil)
(run-hooks 'ess-transcript-mode-hook))
;;*;; Commands used in S transcript mode
(defun ess-transcript-send-command ()
"Send the command at point in the transcript to the ESS process.
The line should begin with a prompt. The ESS process buffer is displayed if it
is not already."
(interactive)
(let* ((proc (or ess-local-process-name
(ess-request-a-process "Evaluate into which process? " t)))
(ess-buf (get-ess-buffer proc)))
(setq ess-local-process-name proc)
(if (get-buffer-window ess-buf) nil
(display-buffer ess-buf t))
(let ((input (inferior-ess-get-old-input)))
(save-excursion
(set-buffer ess-buf)
(goto-char (point-max))
(ess-eval-linewise input)))))
(defun ess-transcript-send-command-and-move ()
"Send the command on this line, and move point to the next command."
(interactive)
;; (ess-transcript-send-command) ;; This doesn't work properly
;; replacement code begins
(let* ((proc (or ess-local-process-name
(ess-request-a-process "Evaluate into which process? " t)))
(ess-buf (get-ess-buffer proc)))
(setq ess-local-process-name proc)
(if (get-buffer-window ess-buf) nil
(display-buffer ess-buf t))
(let ((input (inferior-ess-get-old-input)))
(save-excursion
(set-buffer ess-buf)
(goto-char (point-max))
(ess-eval-linewise input nil nil nil 1))))
;; replacement code ends
(goto-char ess-temp-point)
(comint-next-prompt 1))
(defun ess-transcript-copy-command ()
"Copy the command at point to the command line of the ESS process."
(interactive)
(let* ((proc (or ess-local-process-name
(ess-request-a-process "Evaluate into which process? " t)))
(ess-buf (process-buffer (get-process proc)))
(input (inferior-ess-get-old-input)))
(setq ess-local-process-name proc)
(if (get-buffer-window ess-buf) nil
(display-buffer ess-buf t))
(save-excursion
(set-buffer ess-buf)
(goto-char (point-max))
(insert input)))
(ess-switch-to-end-of-ESS))
(defun ess-transcript-clean-region (beg end even-if-read-only)
"Strip the transcript in the region, leaving only (R/S/Lsp/..) commands.
Deletes any lines not beginning with a prompt, and then removes the
prompt from those lines that remain. Prefix argument means to use
\\[toggle-read-only] to clean even if the buffer is \\[read-only]."
(interactive "r\nP")
(unless inferior-ess-prompt
(error "Cannot clean ESS transcript region in this mode!
That only works in ess-transcript-mode or inferior-ess-mode ('*R*' etc)."
;; Maybe call ess-clean-region-in-new-transcript ?"))
))
(let ((do-toggle (and buffer-read-only even-if-read-only))
(ess-prompt-rx (concat "^" inferior-ess-prompt)))
(save-excursion
(if do-toggle (toggle-read-only 0))
(save-restriction
(unless (featurep 'xemacs) ;; does not exist in xemacs:
(deactivate-mark))
(narrow-to-region beg end)
(goto-char (point-min))
(delete-non-matching-lines ess-prompt-rx)
(goto-char (point-min))
;; (replace-regexp * * ) :
(while (re-search-forward ess-prompt-rx nil t)
(replace-match "" nil nil)))
(if do-toggle (toggle-read-only 1)))))
;; unfinished idea :-----------------------
;; (defun ess-clean-region-in-new-transcript (beg end)
;; "Copy the region into a new ess-transcript buffer, and clean it there,
;; using \\[ess-transcript-clean-region]."
;; (interactive "r")
;; (let ((bname (buffer-file-name)))
;; (setq bname (if bname .. ..))
;; (let
;; (fbase (if fname (file-name-sans-extension (file-name-nondirectory fname))
;; (buffer-name)))
;;
;; ;; the buffer name should be like a file name
;; (buf-nam ....)
;; (trns-buf (get-buffer-create fbase))
;; (pop-to-buffer trns-buf)
;; (ess-transcript-mode .....)
;; )))
(defun ess-transcript-DO-clean-region (beg end)
"Clean the current via \\[ess-transcript-clean-region] even if the buffer is read-only."
(interactive "r")
(ess-transcript-clean-region beg end 'In-ANY-case))
(defun ess-transcript-clean-buffer ()
"Cleanup the whole buffer.
Use point-min/max to obey narrow-to-region."
(interactive)
(ess-transcript-clean-region (point-min) (point-max) 'In-ANY-case))
; Local variables section
;;; This file is automatically placed in Outline minor mode.
;;; The file is structured as follows:
;;; Chapters: ^L ;
;;; Sections: ;;*;;
;;; Subsections: ;;;*;;;
;;; Components: defuns, defvars, defconsts
;;; Random code beginning with a ;;;;* comment
;;; Local variables:
;;; mode: emacs-lisp
;;; mode: outline-minor
;;; outline-regexp: "\^L\\|\\`;\\|;;\\*\\|;;;\\*\\|(def[cvu]\\|(setq\\|;;;;\\*"
;;; End:
;;; ess-trans.el ends here
|