6
6
;; Free Software Foundation, Inc.
8
;; Author: Jesper Nordenberg <mayhem@home.se>
9
;; Klaus Berndl <klaus.berndl@sdm.de>
8
;; Author: Klaus Berndl <klaus.berndl@sdm.de>
10
9
;; Kevin A. Burton <burton@openprivacy.org>
11
10
;; Maintainer: Klaus Berndl <klaus.berndl@sdm.de>
12
;; Kevin A. Burton <burton@openprivacy.org>
13
11
;; Keywords: browser, code, programming, tools
26
24
;; GNU Emacs; see the file COPYING. If not, write to the Free Software
27
25
;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29
;; $Id: ecb-eshell.el,v 1.78 2005/06/20 14:34:20 berndl Exp $
27
;; $Id: ecb-eshell.el,v 1.86 2010/02/23 16:08:56 berndl Exp $
114
112
:group 'ecb-eshell
117
(defcustom ecb-eshell-synchronize t
115
;; TODO: Klaus Berndl <klaus.berndl@sdm.de>: was ecb-eshell-synchronize -->
116
;; rename in texi and also to ecb-upgrade (also with value-upgrade!)
117
(defcustom ecb-eshell-buffer-sync 'basic
118
118
"*Synchronize eshell with the default-directory of current source-buffer.
119
The synchronization is done by `ecb-eshell-current-buffer-sync' which can be
120
called interactively but normally it is called autom. by the
121
`ecb-current-buffer-sync-hook-internal'."
120
This option takes only effect if a permanant compile-window is used in the
123
If 'always then the synchronization takes place always a buffer
124
changes in the edit window and if after this the
125
default-directory of the new edit-buffer is different from the
126
default-directory of the current eshell-buffer. If value is nil
127
then never a synchronization will take place. If a list of
128
major-modes then only if the `major-mode' of the new buffer
129
belongs NOT to this list.
131
If the special value 'basic is set then ECB uses the setting of the option
132
`ecb-basic-buffer-sync'."
134
:type '(radio :tag "Synchronize the eshell if in compile-window."
135
(const :tag "Use basic value" :value basic)
136
(const :tag "Always" :value always)
137
(const :tag "Never" nil)
138
(repeat :tag "Not with these modes"
139
(symbol :tag "mode"))))
142
(defcustom ecb-eshell-buffer-sync-delay 'basic
143
"*Time Emacs must be idle before the eshell-buffer of ECB is synchronized.
144
Synchronizing is done with the current source displayed in the edit window. If
145
nil then there is no delay, means synchronization takes place immediately. A
146
small value of about 0.25 seconds saves CPU resources and you get even though
147
almost the same effect as if you set no delay.
149
If the special value 'basic is set then ECB uses the setting of the option
150
`ecb-basic-buffer-sync-delay'."
152
:type '(radio (const :tag "Use basic value" :value basic)
153
(const :tag "No synchronizing delay" :value nil)
154
(number :tag "Idle time before synchronizing" :value 2))
155
:set (function (lambda (symbol value)
157
(if (and (boundp 'ecb-minor-mode)
159
(ecb-activate-ecb-autocontrol-function
160
value 'ecb-analyse-buffer-sync))))
161
:initialize 'custom-initialize-default)
125
165
(defvar ecb-eshell-pre-command-point nil
126
166
"Point in the buffer we are at before we executed a command.")
131
171
called with an prefix arg!")
134
(defconst ecb-eshell-adviced-functions '((eshell . around))
174
(defecb-advice-set ecb-eshell-adviced-functions
135
175
"These functions of eshell are adviced if ehsell is active during ECB is
136
active. Each element of the list is a cons-cell where the car is the
137
function-symbol and the cdr the advice-class \(before, around or after). If a
138
function should be adviced with more than one class \(e.g. with a before and
139
an after-advice) then for every class a cons must be added to this list.")
141
(defadvice eshell (around ecb)
178
(defecb-advice eshell around ecb-eshell-adviced-functions
142
179
"Ensure that ehsell is running in the ECB-compile-window if any."
143
180
;; we tell ECB to handle the eshell-buffers as compilation-buffers so they
144
181
;; will be displayed in the compile-window (if any). We must add this as
176
213
(ecb-layout-debug-error "eshell around-advice: comp-win will be toggled.")
177
214
(ecb-toggle-compile-window 1))
216
(ecb-activate-ecb-autocontrol-function ecb-eshell-buffer-sync-delay
217
'ecb-eshell-buffer-sync)
180
(add-hook 'ecb-current-buffer-sync-hook-internal
181
'ecb-eshell-current-buffer-sync)
182
219
(add-hook 'eshell-post-command-hook 'ecb-eshell-recenter)
183
220
(add-hook 'eshell-post-command-hook 'ecb-eshell-fit-window-to-output)
184
221
(add-hook 'eshell-pre-command-hook 'ecb-eshell-precommand-hook)
204
241
(ecb-eshell-recenter)
206
243
;;sync to the current buffer
207
(ecb-eshell-current-buffer-sync))
244
(ecb-eshell-buffer-sync))
211
248
(defun ecb-eshell-activate-integration ()
212
249
"Does all necessary to activate the eshell-integration. But this doesn not
213
250
load or activate eshell - it just prepares ECB to work perfectly with eshell."
214
(ecb-enable-advices ecb-eshell-adviced-functions))
251
(ecb-enable-advices 'ecb-eshell-adviced-functions))
216
253
(defun ecb-eshell-deactivate-integration ()
217
(ecb-disable-advices ecb-eshell-adviced-functions)
218
(remove-hook 'ecb-current-buffer-sync-hook-internal
219
'ecb-eshell-current-buffer-sync)
254
(ecb-disable-advices 'ecb-eshell-adviced-functions)
255
(ecb-stop-autocontrol/sync-function 'ecb-eshell-buffer-sync)
220
256
(remove-hook 'eshell-post-command-hook 'ecb-eshell-recenter)
221
257
(remove-hook 'eshell-post-command-hook 'ecb-eshell-fit-window-to-output)
222
258
(remove-hook 'eshell-pre-command-hook 'ecb-eshell-precommand-hook)
223
259
(remove-hook 'window-size-change-functions 'ecb-eshell-window-size-change))
225
(defun ecb-eshell-current-buffer-sync()
261
(defecb-autocontrol/sync-function ecb-eshell-buffer-sync nil ecb-eshell-buffer-sync t
226
262
"Synchronize the eshell with the directory of current source-buffer.
227
263
This is only done if the eshell is currently visible in the compile-window of
228
264
ECB and if either this function is called interactively or
229
`ecb-eshell-synchronize' is not nil."
265
`ecb-eshell-buffer-sync' is not nil."
232
266
(when (and (equal (selected-frame) ecb-frame)
233
(or ecb-eshell-synchronize (interactive-p))
234
267
(ecb-compile-window-live-p)
235
(not (ecb-point-in-compile-window)))
268
(ecb-point-in-edit-window-number))
237
269
(let* ((my-eshell-buffer
238
270
;; nil or a living eshell-buffer in the ecb-compile-window
239
271
(car (member (window-buffer ecb-compile-window)
240
272
ecb-eshell-buffer-list)))
241
273
(my-reference-directory default-directory)
242
274
(my-eshell-directory (and (bufferp my-eshell-buffer)
244
(set-buffer my-eshell-buffer)
275
(with-current-buffer my-eshell-buffer
245
276
default-directory))))
246
277
(when (and (bufferp my-eshell-buffer)
247
278
(stringp my-reference-directory)
249
280
(not (ecb-string= (ecb-fix-filename my-reference-directory)
250
281
(ecb-fix-filename my-eshell-directory))))
251
282
(ecb-eshell-save-buffer-history
253
(set-buffer my-eshell-buffer)
283
(with-current-buffer my-eshell-buffer
254
284
;; make sure we have a clean eshell-command-line
255
285
(goto-char (point-max))
327
357
(ecb-normalize-number ecb-compile-window-height
328
358
(1- (frame-height))))
329
359
(ecb-enlarged-compilation-window-max-height
330
(max (min (save-excursion
331
(set-buffer (window-buffer ecb-compile-window))
360
(max (min (with-current-buffer (window-buffer ecb-compile-window)
332
361
;; we want to see the old command line too and 2
333
362
;; must be added because we have a modeline and one
334
363
;; empty line cause of the (recenter -2) in