forked from jdtsmith/idlwave
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathidlw-roprompt.el
141 lines (126 loc) · 5.06 KB
/
idlw-roprompt.el
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
;; idlw-shell.el --- run IDL as an inferior process of Emacs.
;; Copyright (c) 2002 Free Software Foundation
;; Author: J.D. Smith <[email protected]>
;; Maintainer: J.D. Smith <[email protected]>
;; Version: 1.0
;; Date: $Date: 2003/05/13 18:42:27 $
;; Keywords: processes
;; This file is part of GNU Emacs.
;; GNU Emacs 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.
;; GNU Emacs 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, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary:
;;
;; Advises the appropriate comint function to make the IDL> prompt
;; read-only. This functionality may be available in future versions
;; of comint directy, in which case this file will be obviated.
;;
;; New versions of IDLWAVE, documentation, and more information
;; available from:
;; http://github.com/jdtsmith/idlwave
;;
;; INSTALLATION:
;; =============
;;
;; Follow the instructions in the INSTALL file of the distribution.
;; In short, put this file on your load path and add the following
;; lines to your .emacs file:
;;
;; (add-hook 'idlwave-shell-mode-hook
;; (lambda () (require 'idlw-roprompt)))
;;
;;
;; SOURCE
;; ======
;;
;; The newest version of this file can be found on the maintainers
;; web site.
;;
;; http://github.com/jdtsmith/idlwave
;;
;; DOCUMENTATION
;; =============
;;
;; IDLWAVE is documented online in info format.
;; A printable version of the documentation is available from the
;; maintainers webpage (see under SOURCE)
;;
;;
;; KNOWN PROBLEMS
;; ==============
;;
;; This functionality will probably fail for some future version of
;; comint, given how explicitly
;;
;;--------------------------------------------------------------------------
;;
;;; Code:
(when (fboundp 'comint-snapshot-last-prompt)
(defvar idlwave-shell-save-comint-last-prompt-overlay nil)
(defun idlwave-shell-comint-signal-read-only (overlay after start end
&optional len)
(if (and (not after)
(or (< (overlay-start overlay) start)
(> (overlay-end overlay) end)))
(error "")))
;; Caution: in Emacs <~21.2, a new overlay gets created for each
;; prompt... in later versions, text-properties for old prompts
;; are used instead, and the original overlay is recycled. In
;; this case, we can advise snapshot-prompt to remove the
;; read-only text properties (not the overlay properties), and
;; here we test to ensure the prompt isn't in the same position as
;; the process-mark before removing the read-only stuff.
(defadvice idlwave-shell-comint-filter (around swap-read-only activate)
"Add a read-only equivalency to the last prompt overlay."
; (when (and idlwave-shell-save-comint-last-prompt-overlay
; (not (equal
; (marker-position (process-mark
; (get-buffer-process
; (get-buffer (idlwave-shell-buffer)))))
; (overlay-end
; idlwave-shell-save-comint-last-prompt-overlay))))
; (setq save-overlay idlwave-shell-save-comint-last-prompt-overlay)
;; Remove the read-only status in case comint needs to do
;; something with the prompt area.
(save-current-buffer
(set-buffer (idlwave-shell-buffer))
(when (and idlwave-shell-save-comint-last-prompt-overlay
(not (eq idlwave-shell-save-comint-last-prompt-overlay
comint-last-prompt-overlay)))
(overlay-put idlwave-shell-save-comint-last-prompt-overlay
'insert-in-front-hooks nil)
(overlay-put idlwave-shell-save-comint-last-prompt-overlay
'modification-hooks nil))
(when comint-last-prompt-overlay
(overlay-put comint-last-prompt-overlay 'insert-in-front-hooks nil)
(overlay-put comint-last-prompt-overlay 'modification-hooks nil)))
ad-do-it
(save-current-buffer
(set-buffer (idlwave-shell-buffer))
(when comint-last-prompt-overlay
(setq idlwave-shell-save-comint-last-prompt-overlay
comint-last-prompt-overlay)
(overlay-put comint-last-prompt-overlay 'modification-hooks
'(idlwave-shell-comint-signal-read-only))
(overlay-put comint-last-prompt-overlay 'insert-in-front-hooks
'(idlwave-shell-comint-signal-read-only)))))
(defadvice comint-snapshot-last-prompt (after remove-text-read-only activate)
"Remove the read-only text properties potentially set by snapshot"
(save-current-buffer
(set-buffer (idlwave-shell-buffer))
(when comint-last-prompt-overlay
(remove-text-properties
(overlay-start comint-last-prompt-overlay)
(overlay-end comint-last-prompt-overlay)
'(modification-hooks nil insert-in-front-hooks nil))))))
(provide 'idlw-roprompt)
;;; idlw-roprompt.el ends here