aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlenn Morris2007-10-29 00:40:50 +0000
committerGlenn Morris2007-10-29 00:40:50 +0000
commitac37dedb05e58d1e0958b90e96d15cf71d4fe126 (patch)
treef751a3eeb5ab13379e5f87eaaa5aab89788e9960
parent042be1d3ecaf7014bfb08c42b461f706d3cf9e62 (diff)
downloademacs-ac37dedb05e58d1e0958b90e96d15cf71d4fe126.tar.gz
emacs-ac37dedb05e58d1e0958b90e96d15cf71d4fe126.zip
Update commentary.
(dirtrack-debug): Doc fix. (dirtrack-mode, dirtrack-debug-mode): New names for dirtrack-toggle and dirtrack-debug-toggle. Use define-minor-mode. (dirtrack-toggle, dirtrack-debug-toggle, dirtrackp, dirtrack-debug): Make obsolete. (dirtrack-debug-message): Only print message if dirtrack-debug-mode is non-nil. Use with-current-buffer. (dirtrack): Doc fix. Use dirtrack-mode rather than dirtrackp. Remove dirtrack-debug checks now that dirtrack-debug-message does this.
-rw-r--r--lisp/dirtrack.el109
1 files changed, 47 insertions, 62 deletions
diff --git a/lisp/dirtrack.el b/lisp/dirtrack.el
index 11442d8f6f5..8ca33b340a1 100644
--- a/lisp/dirtrack.el
+++ b/lisp/dirtrack.el
@@ -57,18 +57,12 @@
57;; add 't' as a third element. Note that some of the functions in 57;; add 't' as a third element. Note that some of the functions in
58;; 'comint.el' assume a single-line prompt (eg, comint-bol). 58;; 'comint.el' assume a single-line prompt (eg, comint-bol).
59;; 59;;
60;; Determining this information may take some experimentation. Setting 60;; Determining this information may take some experimentation. Using
61;; the variable `dirtrack-debug' may help; it causes the directory-tracking 61;; `dirtrack-debug-mode' may help; it causes the directory-tracking
62;; filter to log messages to the buffer `dirtrack-debug-buffer'. You can easily 62;; filter to log messages to the buffer `dirtrack-debug-buffer'.
63;; toggle this setting with the `dirtrack-debug-toggle' function.
64;; 63;;
65;; 3) Add a hook to shell-mode to enable the directory tracking: 64;; 3) Activate `dirtrack-mode'. You may wish to turn ordinary shell
66;; 65;; tracking off by calling `shell-dirtrack-mode'.
67;; (add-hook 'shell-mode-hook
68;; (lambda () (add-hook 'comint-preoutput-filter-functions 'dirtrack nil t)))
69;;
70;; You may wish to turn ordinary shell tracking off by calling
71;; `shell-dirtrack-toggle' or setting `shell-dirtrackp'.
72;; 66;;
73;; Examples: 67;; Examples:
74;; 68;;
@@ -147,7 +141,7 @@ be on a single line."
147 :type 'boolean) 141 :type 'boolean)
148 142
149(defcustom dirtrack-debug-buffer "*Directory Tracking Log*" 143(defcustom dirtrack-debug-buffer "*Directory Tracking Log*"
150 "Buffer to write directory tracking debug information." 144 "Buffer in which to write directory tracking debug information."
151 :group 'dirtrack 145 :group 'dirtrack
152 :type 'string) 146 :type 'string)
153 147
@@ -196,49 +190,49 @@ and ends with a forward slash."
196 (concat (match-string 1 dir) ":" (match-string 2 dir)) 190 (concat (match-string 1 dir) ":" (match-string 2 dir))
197 dir)) 191 dir))
198 192
199;; Copied from shell.el 193
200(defun dirtrack-toggle () 194;;;###autoload
201 "Enable or disable Dirtrack directory tracking in a shell buffer." 195(define-minor-mode dirtrack-mode
202 (interactive) 196 "Enable or disable Dirtrack directory tracking in a shell buffer.
203 (if (setq dirtrackp (not dirtrackp)) 197This provides an alternative to `shell-dirtrack-mode'."
198 nil nil nil
199 (if dirtrack-mode
204 (add-hook 'comint-preoutput-filter-functions 'dirtrack nil t) 200 (add-hook 'comint-preoutput-filter-functions 'dirtrack nil t)
205 (remove-hook 'comint-preoutput-filter-functions 'dirtrack t)) 201 (remove-hook 'comint-preoutput-filter-functions 'dirtrack t)))
206 (message "Directory tracking %s" (if dirtrackp "ON" "OFF")))
207 202
208(defun dirtrack-debug-toggle () 203(define-obsolete-function-alias 'dirtrack-toggle 'dirtrack-mode "23.1")
204(define-obsolete-variable-alias 'dirtrackp 'dirtrack-mode "23.1")
205
206
207(define-minor-mode dirtrack-debug-mode
209 "Enable or disable Dirtrack debugging." 208 "Enable or disable Dirtrack debugging."
210 (interactive) 209 nil nil nil
211 (setq dirtrack-debug (not dirtrack-debug)) 210 (if dirtrack-debug-mode
212 (message "Directory debugging %s" (if dirtrack-debug "ON" "OFF")) 211 (display-buffer (get-buffer-create dirtrack-debug-buffer))))
213 (and dirtrack-debug 212
214 (display-buffer (get-buffer-create dirtrack-debug-buffer)))) 213(define-obsolete-function-alias 'dirtrack-debug-toggle 'dirtrack-debug-mode
214 "23.1")
215(define-obsolete-variable-alias 'dirtrack-debug 'dirtrack-debug-mode "23.1")
216
215 217
216(defun dirtrack-debug-message (string) 218(defun dirtrack-debug-message (string)
217 (let ((buf (current-buffer)) 219 "Insert string at the end of `dirtrack-debug-buffer'."
218 (debug-buf (get-buffer-create dirtrack-debug-buffer)) 220 (when dirtrack-debug-mode
219 ) 221 (with-current-buffer (get-buffer-create dirtrack-debug-buffer)
220 (set-buffer debug-buf) 222 (goto-char (point-max))
221 (goto-char (point-max)) 223 (insert (concat string "\n")))))
222 (insert (concat string "\n"))
223 (set-buffer buf)
224 ))
225 224
226;;;###autoload 225;;;###autoload
227(defun dirtrack (input) 226(defun dirtrack (input)
228 "Determine the current directory by scanning the process output for a prompt. 227 "Determine the current directory by scanning the process output for a prompt.
229The prompt to look for is the first item in `dirtrack-list'. 228The prompt to look for is the first item in `dirtrack-list'.
230 229
231You can toggle directory tracking by using the function `dirtrack-toggle'. 230You can toggle directory tracking by using the function `dirtrack-mode'.
232 231
233If directory tracking does not seem to be working, you can use the 232If directory tracking does not seem to be working, you can use the
234function `dirtrack-debug-toggle' to turn on debugging output. 233function `dirtrack-debug-mode' to turn on debugging output."
235 234 (unless (or (null dirtrack-mode)
236You can enable directory tracking by adding this function to 235 (eq (point) (point-min))) ; no output?
237`comint-output-filter-functions'."
238 (if (or (null dirtrackp)
239 ;; No output?
240 (eq (point) (point-min)))
241 nil
242 (let (prompt-path 236 (let (prompt-path
243 (current-dir default-directory) 237 (current-dir default-directory)
244 (dirtrack-regexp (nth 0 dirtrack-list)) 238 (dirtrack-regexp (nth 0 dirtrack-list))
@@ -247,40 +241,31 @@ You can enable directory tracking by adding this function to
247 (multi-line (nth 2 dirtrack-list))) 241 (multi-line (nth 2 dirtrack-list)))
248 (save-excursion 242 (save-excursion
249 ;; No match 243 ;; No match
250 (if (null (string-match dirtrack-regexp input)) 244 (if (not (string-match dirtrack-regexp input))
251 (and dirtrack-debug 245 (dirtrack-debug-message
252 (dirtrack-debug-message 246 (format "Input `%s' failed to match `dirtrack-regexp'" input))
253 (format
254 "Input `%s' failed to match `dirtrack-regexp'" input)))
255 (setq prompt-path (match-string match-num input)) 247 (setq prompt-path (match-string match-num input))
256 ;; Empty string 248 ;; Empty string
257 (if (not (> (length prompt-path) 0)) 249 (if (not (> (length prompt-path) 0))
258 (and dirtrack-debug 250 (dirtrack-debug-message "Match is empty string")
259 (dirtrack-debug-message "Match is empty string"))
260 ;; Transform prompts into canonical forms 251 ;; Transform prompts into canonical forms
261 (setq prompt-path (funcall dirtrack-directory-function 252 (setq prompt-path (funcall dirtrack-directory-function
262 prompt-path)) 253 prompt-path)
263 (setq current-dir (funcall dirtrack-canonicalize-function 254 current-dir (funcall dirtrack-canonicalize-function
264 current-dir)) 255 current-dir))
265 (and dirtrack-debug 256 (dirtrack-debug-message
266 (dirtrack-debug-message 257 (format "Prompt is %s\nCurrent directory is %s"
267 (format 258 prompt-path current-dir))
268 "Prompt is %s\nCurrent directory is %s"
269 prompt-path current-dir)))
270 ;; Compare them 259 ;; Compare them
271 (if (or (string= current-dir prompt-path) 260 (if (or (string= current-dir prompt-path)
272 (string= current-dir 261 (string= current-dir (abbreviate-file-name prompt-path)))
273 (abbreviate-file-name prompt-path))) 262 (dirtrack-debug-message (format "Not changing directory"))
274 (and dirtrack-debug
275 (dirtrack-debug-message
276 (format "Not changing directory")))
277 ;; It's possible that Emacs will think the directory 263 ;; It's possible that Emacs will think the directory
278 ;; won't exist (eg, rlogin buffers) 264 ;; won't exist (eg, rlogin buffers)
279 (if (file-accessible-directory-p prompt-path) 265 (if (file-accessible-directory-p prompt-path)
280 ;; Change directory 266 ;; Change directory
281 (and (shell-process-cd prompt-path) 267 (and (shell-process-cd prompt-path)
282 (run-hooks 'dirtrack-directory-change-hook) 268 (run-hooks 'dirtrack-directory-change-hook)
283 dirtrack-debug
284 (dirtrack-debug-message 269 (dirtrack-debug-message
285 (format "Changing directory to %s" prompt-path))) 270 (format "Changing directory to %s" prompt-path)))
286 (error "Directory %s does not exist" prompt-path))) 271 (error "Directory %s does not exist" prompt-path)))