Mercurial > emacs
annotate lisp/net/tramp-util.el @ 88323:da4ae7e898f6
*** empty log message ***
author | Alex Schroeder <alex@gnu.org> |
---|---|
date | Wed, 01 Mar 2006 07:10:01 +0000 |
parents | d7ddb3e565de |
children |
rev | line source |
---|---|
88155 | 1 ;;; -*- coding: iso-2022-7bit; -*- |
48973
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
diff
changeset
|
2 ;;; tramp-util.el --- Misc utility functions to use with Tramp |
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
diff
changeset
|
3 |
88155 | 4 ;; Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. |
48973
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
diff
changeset
|
5 |
88155 | 6 ;; Author: kai.grossjohann@gmx.net |
48973
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
diff
changeset
|
7 ;; Keywords: comm, extensions, processes |
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
diff
changeset
|
8 |
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
diff
changeset
|
9 ;; This file is free software; you can redistribute it and/or modify |
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
diff
changeset
|
10 ;; it under the terms of the GNU General Public License as published by |
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
diff
changeset
|
11 ;; the Free Software Foundation; either version 2, or (at your option) |
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
diff
changeset
|
12 ;; any later version. |
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
diff
changeset
|
13 |
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
diff
changeset
|
14 ;; This file is distributed in the hope that it will be useful, |
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
diff
changeset
|
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
diff
changeset
|
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
diff
changeset
|
17 ;; GNU General Public License for more details. |
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
diff
changeset
|
18 |
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
diff
changeset
|
19 ;; You should have received a copy of the GNU General Public License |
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
diff
changeset
|
20 ;; along with GNU Emacs; see the file COPYING. If not, write to |
88155 | 21 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
22 ;; Boston, MA 02110-1301, USA. | |
48973
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
diff
changeset
|
23 |
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
diff
changeset
|
24 ;;; Commentary: |
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
diff
changeset
|
25 |
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
diff
changeset
|
26 ;; Some misc. utility functions that might go nicely with Tramp. |
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
diff
changeset
|
27 ;; Mostly, these are kluges awaiting real solutions later on. |
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
diff
changeset
|
28 |
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
diff
changeset
|
29 ;;; Code: |
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
diff
changeset
|
30 |
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
diff
changeset
|
31 (eval-when-compile (require 'cl)) |
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
diff
changeset
|
32 (require 'compile) |
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
diff
changeset
|
33 (require 'tramp) |
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
diff
changeset
|
34 |
88155 | 35 ;; Define a Tramp minor mode. It's intention is to redefine some keys for Tramp |
36 ;; specific functions, like compilation. | |
37 ;; The key remapping works since Emacs 22 only. Unknown for XEmacs. | |
38 | |
39 ;; Pacify byte-compiler | |
40 (eval-when-compile | |
41 (unless (fboundp 'define-minor-mode) | |
42 (defalias 'define-minor-mode 'identity) | |
43 (defvar tramp-minor-mode)) | |
44 (unless (featurep 'xemacs) | |
45 (defalias 'add-menu-button 'identity))) | |
46 | |
47 (defvar tramp-minor-mode-map (make-sparse-keymap) | |
48 "Keymap for Tramp minor mode.") | |
49 | |
50 (define-minor-mode tramp-minor-mode "Tramp minor mode for utility functions." | |
51 :group 'tramp | |
52 :global nil | |
53 :init-value nil | |
54 :lighter " Tramp" | |
55 :keymap tramp-minor-mode-map | |
56 (setq tramp-minor-mode | |
57 (and tramp-minor-mode (tramp-tramp-file-p default-directory)))) | |
58 | |
59 (add-hook 'find-file-hooks 'tramp-minor-mode t) | |
60 (add-hook 'dired-mode-hook 'tramp-minor-mode t) | |
61 | |
62 (defun tramp-remap-command (old-command new-command) | |
63 "Replaces bindings of OLD-COMMAND by NEW-COMMAND. | |
64 If remapping functionality for keymaps is defined, this happens for all | |
65 bindings. Otherwise, only bindings active during invocation are taken | |
66 into account. XEmacs menubar bindings are not changed by this." | |
67 (if (functionp 'command-remapping) | |
68 ;; Emacs 22 | |
69 (eval | |
70 `(define-key tramp-minor-mode-map [remap ,old-command] new-command)) | |
71 ;; previous Emacs versions. | |
72 (mapcar | |
73 '(lambda (x) | |
74 (define-key tramp-minor-mode-map x new-command)) | |
75 (where-is-internal old-command)))) | |
76 | |
77 (tramp-remap-command 'compile 'tramp-compile) | |
78 (tramp-remap-command 'recompile 'tramp-recompile) | |
79 | |
80 ;; XEmacs has an own mimic for menu entries | |
81 (when (fboundp 'add-menu-button) | |
82 (funcall 'add-menu-button | |
83 '("Tools" "Compile") | |
84 ["Compile..." | |
85 (command-execute (if tramp-minor-mode 'tramp-compile 'compile)) | |
86 :active (fboundp 'compile)]) | |
87 (funcall 'add-menu-button | |
88 '("Tools" "Compile") | |
89 ["Repeat Compilation" | |
90 (command-execute (if tramp-minor-mode 'tramp-recompile 'recompile)) | |
91 :active (fboundp 'compile)])) | |
92 | |
93 ;; Utility functions. | |
94 | |
48973
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
diff
changeset
|
95 (defun tramp-compile (command) |
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
diff
changeset
|
96 "Compile on remote host." |
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
diff
changeset
|
97 (interactive |
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
diff
changeset
|
98 (if (or compilation-read-command current-prefix-arg) |
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
diff
changeset
|
99 (list (read-from-minibuffer "Compile command: " |
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
diff
changeset
|
100 compile-command nil nil |
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
diff
changeset
|
101 '(compile-history . 1))) |
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
diff
changeset
|
102 (list compile-command))) |
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
diff
changeset
|
103 (setq compile-command command) |
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
diff
changeset
|
104 (save-some-buffers (not compilation-ask-about-save) nil) |
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
diff
changeset
|
105 (let ((d default-directory)) |
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
diff
changeset
|
106 (save-excursion |
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
diff
changeset
|
107 (pop-to-buffer (get-buffer-create "*Compilation*") t) |
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
diff
changeset
|
108 (erase-buffer) |
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
diff
changeset
|
109 (setq default-directory d))) |
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
diff
changeset
|
110 (tramp-handle-shell-command command (get-buffer "*Compilation*")) |
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
diff
changeset
|
111 (pop-to-buffer (get-buffer "*Compilation*")) |
88155 | 112 (tramp-minor-mode 1) |
113 (compilation-minor-mode 1)) | |
114 | |
115 (defun tramp-recompile () | |
116 "Re-compile on remote host." | |
117 (interactive) | |
118 (save-some-buffers (not compilation-ask-about-save) nil) | |
119 (tramp-handle-shell-command compile-command (get-buffer "*Compilation*")) | |
120 (pop-to-buffer (get-buffer "*Compilation*")) | |
121 (tramp-minor-mode 1) | |
48973
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
diff
changeset
|
122 (compilation-minor-mode 1)) |
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
diff
changeset
|
123 |
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
diff
changeset
|
124 (provide 'tramp-util) |
88155 | 125 |
126 ;;; arch-tag: 500f9992-a44e-46d0-83a7-980799251808 | |
48973
09acf3f65bb5
* net/tramp*.el: Sync with upstream version 2.0.28. Bugfixes.
Kai Großjohann <kgrossjo@eu.uu.net>
parents:
diff
changeset
|
127 ;;; tramp-util.el ends here |