summaryrefslogtreecommitdiff
path: root/lisp/net
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/net')
-rw-r--r--lisp/net/ange-ftp.el16
-rw-r--r--lisp/net/browse-url.el24
-rw-r--r--lisp/net/dbus.el65
-rw-r--r--lisp/net/dig.el18
-rw-r--r--lisp/net/eudc.el19
-rw-r--r--lisp/net/eww.el80
-rw-r--r--lisp/net/gnutls.el154
-rw-r--r--lisp/net/html2text.el461
-rw-r--r--lisp/net/mailcap.el1111
-rw-r--r--lisp/net/net-utils.el44
-rw-r--r--lisp/net/network-stream.el89
-rw-r--r--lisp/net/newst-backend.el7
-rw-r--r--lisp/net/newsticker.el2
-rw-r--r--lisp/net/nsm.el47
-rw-r--r--lisp/net/ntlm.el160
-rw-r--r--lisp/net/pop3.el915
-rw-r--r--lisp/net/puny.el248
-rw-r--r--lisp/net/quickurl.el52
-rw-r--r--lisp/net/rcirc.el47
-rw-r--r--lisp/net/secrets.el58
-rw-r--r--lisp/net/shr.el419
-rw-r--r--lisp/net/sieve-manage.el583
-rw-r--r--lisp/net/sieve-mode.el212
-rw-r--r--lisp/net/sieve.el373
-rw-r--r--lisp/net/soap-client.el122
-rw-r--r--lisp/net/starttls.el304
-rw-r--r--lisp/net/tramp-adb.el278
-rw-r--r--lisp/net/tramp-cache.el116
-rw-r--r--lisp/net/tramp-cmds.el49
-rw-r--r--lisp/net/tramp-compat.el641
-rw-r--r--lisp/net/tramp-ftp.el30
-rw-r--r--lisp/net/tramp-gvfs.el696
-rw-r--r--lisp/net/tramp-gw.el336
-rw-r--r--lisp/net/tramp-sh.el1203
-rw-r--r--lisp/net/tramp-smb.el274
-rw-r--r--lisp/net/tramp.el1465
-rw-r--r--lisp/net/trampver.el47
-rw-r--r--lisp/net/webjump.el209
38 files changed, 7414 insertions, 3560 deletions
diff --git a/lisp/net/ange-ftp.el b/lisp/net/ange-ftp.el
index 239da7829df..07c3daf7d7e 100644
--- a/lisp/net/ange-ftp.el
+++ b/lisp/net/ange-ftp.el
@@ -1533,12 +1533,11 @@ then kill the related FTP process."
(defun ange-ftp-barf-if-not-directory (directory)
(or (file-directory-p directory)
- (signal 'file-error
- (list "Opening directory"
- (if (file-exists-p directory)
- "Not a directory"
- "No such file or directory")
- directory))))
+ (let ((exists (file-exists-p directory)))
+ (signal (if exists 'file-error 'file-missing)
+ (list "Opening directory"
+ (if exists "Not a directory" "No such file or directory")
+ directory)))))
;;;; ------------------------------------------------------------
;;;; FTP process filter support.
@@ -3352,9 +3351,10 @@ system TYPE.")
(setq buffer-file-name filename)))
(setq last-coding-system-used coding-system-used)
(list filename size))
- (signal 'file-error
+ (signal 'file-missing
(list
"Opening input file"
+ "No such file or directory"
filename))))
(ange-ftp-real-insert-file-contents filename visit beg end replace))))
@@ -3663,7 +3663,7 @@ so return the size on the remote host exactly. See RFC 3659."
newname (expand-file-name newname))
(or (file-exists-p filename)
- (signal 'file-error
+ (signal 'file-missing
(list "Copy file" "No such file or directory" filename)))
;; canonicalize newname if a directory.
diff --git a/lisp/net/browse-url.el b/lisp/net/browse-url.el
index 68258d41666..b2077d784c0 100644
--- a/lisp/net/browse-url.el
+++ b/lisp/net/browse-url.el
@@ -184,6 +184,15 @@ be used instead."
:version "24.1"
:group 'browse-url)
+(defcustom browse-url-man-function 'browse-url-man
+ "Function to display man: links."
+ :type '(radio
+ (function-item :tag "Emacs Man" :value browse-url-man)
+ (const :tag "None" nil)
+ (function :tag "Other function"))
+ :version "26.1"
+ :group 'browse-url)
+
(defcustom browse-url-netscape-program "netscape"
;; Info about netscape-remote from Karl Berry.
"The name by which to invoke Netscape.
@@ -798,6 +807,8 @@ as ARGS."
(let ((process-environment (copy-sequence process-environment))
(function (or (and (string-match "\\`mailto:" url)
browse-url-mailto-function)
+ (and (string-match "\\`man:" url)
+ browse-url-man-function)
browse-url-browser-function))
;; Ensure that `default-directory' exists and is readable (b#6077).
(default-directory (or (unhandled-file-name-directory default-directory)
@@ -1585,6 +1596,19 @@ used instead of `browse-url-new-window-flag'."
(unless (bolp)
(insert "\n"))))))))
+;; --- man ---
+
+(defvar manual-program)
+
+(defun browse-url-man (url &optional _new-window)
+ "Open a man page."
+ (interactive (browse-url-interactive-arg "Man page URL: "))
+ (require 'man)
+ (setq url (replace-regexp-in-string "\\`man:" "" url))
+ (cond
+ ((executable-find manual-program) (man url))
+ (t (woman (replace-regexp-in-string "([[:alnum:]]+)" "" url)))))
+
;; --- Random browser ---
;;;###autoload
diff --git a/lisp/net/dbus.el b/lisp/net/dbus.el
index 7a4ef1f7bcf..2d7cd2fc612 100644
--- a/lisp/net/dbus.el
+++ b/lisp/net/dbus.el
@@ -1,4 +1,4 @@
-;;; dbus.el --- Elisp bindings for D-Bus.
+;;; dbus.el --- Elisp bindings for D-Bus. -*- lexical-binding: t -*-
;; Copyright (C) 2007-2016 Free Software Foundation, Inc.
@@ -492,7 +492,7 @@ See `dbus-registered-objects-table' for a description of the
hash table."
(let (result)
(maphash
- (lambda (key value) (add-to-list 'result (cons key value) 'append))
+ (lambda (key value) (push (cons key value) result))
dbus-registered-objects-table)
result))
@@ -1113,9 +1113,9 @@ unique names for services."
"Retrieve all services which correspond to a known name in BUS.
A service has a known name if it doesn't start with \":\"."
(let (result)
- (dolist (name (dbus-list-names bus) result)
+ (dolist (name (dbus-list-names bus) (nreverse result))
(unless (string-equal ":" (substring name 0 1))
- (add-to-list 'result name 'append)))))
+ (push name result)))))
(defun dbus-list-queued-owners (bus service)
"Return the unique names registered at D-Bus BUS and queued for SERVICE.
@@ -1214,9 +1214,8 @@ It returns a list of strings. The node names stand for further
object paths of the D-Bus service."
(let ((object (dbus-introspect-xml bus service path))
result)
- (dolist (elt (xml-get-children object 'node) result)
- (add-to-list
- 'result (dbus-introspect-get-attribute elt "name") 'append))))
+ (dolist (elt (xml-get-children object 'node) (nreverse result))
+ (push (dbus-introspect-get-attribute elt "name") result))))
(defun dbus-introspect-get-all-nodes (bus service path)
"Return all node names of SERVICE in D-Bus BUS at object path PATH.
@@ -1240,9 +1239,8 @@ interface is \"org.freedesktop.DBus.Properties\". If present,
children, beside \"method\" and \"signal\" objects."
(let ((object (dbus-introspect-xml bus service path))
result)
- (dolist (elt (xml-get-children object 'interface) result)
- (add-to-list
- 'result (dbus-introspect-get-attribute elt "name") 'append))))
+ (dolist (elt (xml-get-children object 'interface) (nreverse result))
+ (push (dbus-introspect-get-attribute elt "name") result))))
(defun dbus-introspect-get-interface (bus service path interface)
"Return the INTERFACE of SERVICE in D-Bus BUS at object path PATH.
@@ -1264,9 +1262,8 @@ The resulting \"interface\" object can contain \"method\", \"signal\",
SERVICE is a service of D-Bus BUS at object path PATH."
(let ((object (dbus-introspect-get-interface bus service path interface))
result)
- (dolist (elt (xml-get-children object 'method) result)
- (add-to-list
- 'result (dbus-introspect-get-attribute elt "name") 'append))))
+ (dolist (elt (xml-get-children object 'method) (nreverse result))
+ (push (dbus-introspect-get-attribute elt "name") result))))
(defun dbus-introspect-get-method (bus service path interface method)
"Return method METHOD of interface INTERFACE as XML object.
@@ -1288,9 +1285,8 @@ object can contain \"arg\" and \"annotation\" children."
SERVICE is a service of D-Bus BUS at object path PATH."
(let ((object (dbus-introspect-get-interface bus service path interface))
result)
- (dolist (elt (xml-get-children object 'signal) result)
- (add-to-list
- 'result (dbus-introspect-get-attribute elt "name") 'append))))
+ (dolist (elt (xml-get-children object 'signal) (nreverse result))
+ (push (dbus-introspect-get-attribute elt "name") result))))
(defun dbus-introspect-get-signal (bus service path interface signal)
"Return signal SIGNAL of interface INTERFACE as XML object.
@@ -1312,9 +1308,8 @@ object can contain \"arg\" and \"annotation\" children."
SERVICE is a service of D-Bus BUS at object path PATH."
(let ((object (dbus-introspect-get-interface bus service path interface))
result)
- (dolist (elt (xml-get-children object 'property) result)
- (add-to-list
- 'result (dbus-introspect-get-attribute elt "name") 'append))))
+ (dolist (elt (xml-get-children object 'property) (nreverse result))
+ (push (dbus-introspect-get-attribute elt "name") result))))
(defun dbus-introspect-get-property (bus service path interface property)
"This function returns PROPERTY of INTERFACE as XML object.
@@ -1345,9 +1340,8 @@ object, where the annotations belong to."
(dbus-introspect-get-property bus service path interface name))
(dbus-introspect-get-interface bus service path interface)))
result)
- (dolist (elt (xml-get-children object 'annotation) result)
- (add-to-list
- 'result (dbus-introspect-get-attribute elt "name") 'append))))
+ (dolist (elt (xml-get-children object 'annotation) (nreverse result))
+ (push (dbus-introspect-get-attribute elt "name") result))))
(defun dbus-introspect-get-annotation
(bus service path interface name annotation)
@@ -1382,9 +1376,8 @@ therefore, even if the method or signal has arguments."
(or (dbus-introspect-get-method bus service path interface name)
(dbus-introspect-get-signal bus service path interface name)))
result)
- (dolist (elt (xml-get-children object 'arg) result)
- (add-to-list
- 'result (dbus-introspect-get-attribute elt "name") 'append))))
+ (dolist (elt (xml-get-children object 'arg) (nreverse result))
+ (push (dbus-introspect-get-attribute elt "name") result))))
(defun dbus-introspect-get-argument (bus service path interface name arg)
"Return argument ARG as XML object.
@@ -1473,8 +1466,8 @@ nil is returned."
(dbus-call-method
bus service path dbus-interface-properties
"GetAll" :timeout 500 interface)
- result)
- (add-to-list 'result (cons (car dict) (cl-caadr dict)) 'append)))))
+ (nreverse result))
+ (push (cons (car dict) (cl-caadr dict)) result)))))
(defun dbus-register-property
(bus service path interface property access value
@@ -1609,11 +1602,11 @@ It will be registered for all objects created by `dbus-register-property'."
(when (and (equal (butlast key) (list :property bus interface))
(string-equal path (nth 2 (car val)))
(not (functionp (car (last (car val))))))
- (add-to-list
- 'result
+ (push
(list :dict-entry
(car (last key))
- (list :variant (cdar (last (car val))))))))
+ (list :variant (cdar (last (car val)))))
+ result)))
dbus-registered-objects-table)
;; Return the result, or an empty array.
(list :array (or result '(:signature "{sv}"))))))))
@@ -1684,12 +1677,12 @@ and \"org.freedesktop.DBus.Properties.GetAll\", which is slow."
(interface
(dbus-introspect-get-interface-names bus service object)
result1)
- (add-to-list
- 'result1
+ (push
(cons interface
- (dbus-get-all-properties bus service object interface))))
+ (dbus-get-all-properties bus service object interface))
+ result1))
(when result1
- (add-to-list 'result (cons object result1))))))))
+ (push (cons object result1) result)))))))
(defun dbus-managed-objects-handler ()
"Default handler for the \"org.freedesktop.DBus.ObjectManager\" interface.
@@ -1705,7 +1698,7 @@ It will be registered for all objects created by `dbus-register-service'."
(lambda (key val)
(when (and (equal (butlast key 2) (list :method bus))
(null (nth 2 (car-safe val))))
- (add-to-list 'interfaces (nth 2 key))))
+ (push (nth 2 key) interfaces)))
dbus-registered-objects-table)
;; Check all registered object paths.
@@ -1716,7 +1709,7 @@ It will be registered for all objects created by `dbus-register-service'."
(string-prefix-p path object))
(dolist (interface (cons (nth 2 key) interfaces))
(unless (assoc object result)
- (add-to-list 'result (list object)))
+ (push (list object) result))
(unless (assoc interface (cdr (assoc object result)))
(setcdr
(assoc object result)
diff --git a/lisp/net/dig.el b/lisp/net/dig.el
index 02cb627cfd3..338afca15f1 100644
--- a/lisp/net/dig.el
+++ b/lisp/net/dig.el
@@ -36,8 +36,6 @@
;;; Code:
-(eval-when-compile (require 'cl))
-
(defgroup dig nil
"Dig configuration."
:group 'comm)
@@ -126,15 +124,13 @@ Buffer should contain output generated by `dig-invoke'."
;; `font-lock-defaults' buffer-local variable.
(put 'dig-mode 'font-lock-defaults '(dig-font-lock-keywords t))
-(put 'dig-mode 'mode-class 'special)
-
(defvar dig-mode-map
(let ((map (make-sparse-keymap)))
- (suppress-keymap map)
+ (define-key map "g" nil)
(define-key map "q" 'dig-exit)
map))
-(define-derived-mode dig-mode nil "Dig"
+(define-derived-mode dig-mode special-mode "Dig"
"Major mode for displaying dig output."
(buffer-disable-undo)
(unless (featurep 'xemacs)
@@ -148,7 +144,7 @@ Buffer should contain output generated by `dig-invoke'."
(defun dig-exit ()
"Quit dig output buffer."
(interactive)
- (kill-buffer (current-buffer)))
+ (quit-window t))
;;;###autoload
(defun dig (domain &optional
@@ -156,14 +152,12 @@ Buffer should contain output generated by `dig-invoke'."
"Query addresses of a DOMAIN using dig, by calling `dig-invoke'.
Optional arguments are passed to `dig-invoke'."
(interactive "sHost: ")
- (switch-to-buffer
+ (pop-to-buffer-same-window
(dig-invoke domain query-type query-class query-option dig-option server))
(goto-char (point-min))
(and (search-forward ";; ANSWER SECTION:" nil t)
(forward-line))
- (dig-mode)
- (setq buffer-read-only t)
- (set-buffer-modified-p nil))
+ (dig-mode))
;; named for consistency with query-dns in dns.el
(defun query-dig (domain &optional
@@ -175,7 +169,7 @@ Returns nil for domain/class/type queries that result in no data."
(let ((buffer (dig-invoke domain query-type query-class
query-option dig-option server)))
(when buffer
- (switch-to-buffer buffer)
+ (pop-to-buffer-same-window buffer)
(let ((digger (dig-extract-rr domain query-type query-class)))
(kill-buffer buffer)
digger))))
diff --git a/lisp/net/eudc.el b/lisp/net/eudc.el
index 867bea98e77..22e48dbd3d3 100644
--- a/lisp/net/eudc.el
+++ b/lisp/net/eudc.el
@@ -1146,7 +1146,7 @@ queries the server for the existing fields and displays a corresponding form."
(defun eudc-menu ()
(let (command)
- (append '("Directory Search")
+ (append '("Directory Servers")
(list
(append
'("Server")
@@ -1186,8 +1186,8 @@ queries the server for the existing fields and displays a corresponding form."
(define-key
global-map
[menu-bar tools directory-search]
- (cons "Directory Search"
- (easy-menu-create-menu "Directory Search" (cdr (eudc-menu))))))
+ (cons "Directory Servers"
+ (easy-menu-create-menu "Directory Servers" (cdr (eudc-menu))))))
((fboundp 'easy-menu-add-item)
(let ((menu (eudc-menu)))
(easy-menu-add-item nil '("tools") (easy-menu-create-menu (car menu)
@@ -1197,8 +1197,9 @@ queries the server for the existing fields and displays a corresponding form."
(define-key
global-map
[menu-bar tools eudc]
- (cons "Directory Search"
- (easy-menu-create-keymaps "Directory Search" (cdr (eudc-menu))))))
+ (cons "Directory Servers"
+ (easy-menu-create-keymaps "Directory Servers"
+ (cdr (eudc-menu))))))
(t
(error "Unknown version of easymenu"))))
))
@@ -1231,7 +1232,7 @@ This does nothing except loading eudc by autoload side-effect."
(cond
((not (featurep 'xemacs))
(defvar eudc-tools-menu
- (let ((map (make-sparse-keymap "Directory Search")))
+ (let ((map (make-sparse-keymap "Directory Servers")))
(define-key map [phone]
`(menu-item ,(purecopy "Get Phone") eudc-get-phone
:help ,(purecopy "Get the phone field of name from the directory server")))
@@ -1255,7 +1256,7 @@ This does nothing except loading eudc by autoload side-effect."
map))
(fset 'eudc-tools-menu (symbol-value 'eudc-tools-menu)))
(t
- (let ((menu '("Directory Search"
+ (let ((menu '("Directory Servers"
["Load Hotlist of Servers" eudc-load-eudc t]
["New Server" eudc-set-server t]
["---" nil nil]
@@ -1279,8 +1280,8 @@ This does nothing except loading eudc by autoload side-effect."
(define-key
global-map
[menu-bar tools eudc]
- (cons "Directory Search"
- (easy-menu-create-keymaps "Directory Search"
+ (cons "Directory Servers"
+ (easy-menu-create-keymaps "Directory Servers"
(cdr menu)))))))))))
;;}}}
diff --git a/lisp/net/eww.el b/lisp/net/eww.el
index 620a8a5f9ac..7672bf0e1ef 100644
--- a/lisp/net/eww.el
+++ b/lisp/net/eww.el
@@ -24,13 +24,14 @@
;;; Code:
-(eval-when-compile (require 'cl))
+(require 'cl-lib)
(require 'format-spec)
(require 'shr)
(require 'url)
(require 'url-queue)
(require 'url-util) ; for url-get-url-at-point
(require 'mm-url)
+(require 'puny)
(eval-when-compile (require 'subr-x)) ;; for string-trim
(defgroup eww nil
@@ -73,8 +74,8 @@ duplicate entries (if any) removed."
:group 'eww
:type 'hook
:options '(eww-links-at-point
- url-get-url-at-point
- eww-current-url))
+ url-get-url-at-point
+ eww-current-url))
(defcustom eww-bookmarks-directory user-emacs-directory
"Directory where bookmark files will be stored."
@@ -222,7 +223,7 @@ See also `eww-form-checkbox-selected-symbol'."
"When this regex is found in the URL, it's not a keyword but an address.")
(defvar eww-link-keymap
- (let ((map (copy-keymap shr-map)))
+ (let ((map (copy-keymap shr-image-map)))
(define-key map "\r" 'eww-follow-link)
map))
@@ -279,6 +280,13 @@ word(s) will be searched for via `eww-search-prefix'."
(current-buffer)
(get-buffer-create "*eww*")))
(eww-setup-buffer)
+ ;; Check whether the domain only uses "Highly Restricted" Unicode
+ ;; IDNA characters. If not, transform to punycode to indicate that
+ ;; there may be funny business going on.
+ (let ((parsed (url-generic-parse-url url)))
+ (unless (puny-highly-restrictive-domain-p (url-host parsed))
+ (setf (url-host parsed) (puny-encode-domain (url-host parsed)))
+ (setq url (url-recreate-url parsed))))
(plist-put eww-data :url url)
(plist-put eww-data :title "")
(eww-update-header-line-format)
@@ -306,6 +314,20 @@ See the `eww-search-prefix' variable for the search engine used."
(interactive "r")
(eww (buffer-substring beg end)))
+(defun eww-open-in-new-buffer ()
+ "Fetch link at point in a new EWW buffer."
+ (interactive)
+ (let ((url (eww-suggested-uris)))
+ (if (null url) (user-error "No link at point")
+ ;; clone useful to keep history, but
+ ;; should not clone from non-eww buffer
+ (with-current-buffer
+ (if (eq major-mode 'eww-mode) (clone-buffer)
+ (generate-new-buffer "*eww*"))
+ (unless (equal url (eww-current-url))
+ (eww-mode)
+ (eww (if (consp url) (car url) url)))))))
+
(defun eww-html-p (content-type)
"Return non-nil if CONTENT-TYPE designates an HTML content type.
Currently this means either text/html or application/xhtml+xml."
@@ -410,7 +432,7 @@ Currently this means either text/html or application/xhtml+xml."
(source (and (null document)
(buffer-substring (point) (point-max)))))
(with-current-buffer buffer
- (setq bidi-paragraph-direction 'left-to-right)
+ (setq bidi-paragraph-direction nil)
(plist-put eww-data :source source)
(plist-put eww-data :dom document)
(let ((inhibit-read-only t)
@@ -418,9 +440,11 @@ Currently this means either text/html or application/xhtml+xml."
(shr-target-id (url-target (url-generic-parse-url url)))
(shr-external-rendering-functions
(append
+ shr-external-rendering-functions
'((title . eww-tag-title)
(form . eww-tag-form)
(input . eww-tag-input)
+ (button . eww-form-submit)
(textarea . eww-tag-textarea)
(select . eww-tag-select)
(link . eww-tag-link)
@@ -570,7 +594,7 @@ Currently this means either text/html or application/xhtml+xml."
(let ((inhibit-read-only t))
(remove-overlays)
(erase-buffer))
- (setq bidi-paragraph-direction 'left-to-right)
+ (setq bidi-paragraph-direction nil)
(unless (eq major-mode 'eww-mode)
(eww-mode)))
@@ -659,11 +683,13 @@ the like."
(setq score (- (length (split-string (dom-text node))))))
(t
(dolist (elem (dom-children node))
- (if (stringp elem)
- (setq score (+ score (length (split-string elem))))
+ (cond
+ ((stringp elem)
+ (setq score (+ score (length (split-string elem)))))
+ ((consp elem)
(setq score (+ score
(or (cdr (assoc :eww-readability-score (cdr elem)))
- (eww-score-readability elem))))))))
+ (eww-score-readability elem)))))))))
;; Cache the score of the node to avoid recomputing all the time.
(dom-set-attribute node :eww-readability-score score)
score))
@@ -685,6 +711,7 @@ the like."
(let ((map (make-sparse-keymap)))
(define-key map "g" 'eww-reload) ;FIXME: revert-buffer-function instead!
(define-key map "G" 'eww)
+ (define-key map [?\M-\r] 'eww-open-in-new-buffer)
(define-key map [?\t] 'shr-next-link)
(define-key map [?\M-\t] 'shr-previous-link)
(define-key map [backtab] 'shr-previous-link)
@@ -703,9 +730,11 @@ the like."
(define-key map "R" 'eww-readable)
(define-key map "H" 'eww-list-histories)
(define-key map "E" 'eww-set-character-encoding)
+ (define-key map "s" 'eww-switch-to-buffer)
(define-key map "S" 'eww-list-buffers)
(define-key map "F" 'eww-toggle-fonts)
(define-key map "D" 'eww-toggle-paragraph-direction)
+ (define-key map [(meta C)] 'eww-toggle-colors)
(define-key map "b" 'eww-add-bookmark)
(define-key map "B" 'eww-list-bookmarks)
@@ -717,6 +746,7 @@ the like."
["Exit" quit-window t]
["Close browser" quit-window t]
["Reload" eww-reload t]
+ ["Follow URL in new buffer" eww-open-in-new-buffer]
["Back to previous page" eww-back-url
:active (not (zerop (length eww-history)))]
["Forward to next page" eww-forward-url
@@ -726,10 +756,13 @@ the like."
["View page source" eww-view-source]
["Copy page URL" eww-copy-page-url t]
["List histories" eww-list-histories t]
+ ["Switch to buffer" eww-switch-to-buffer t]
["List buffers" eww-list-buffers t]
["Add bookmark" eww-add-bookmark t]
["List bookmarks" eww-list-bookmarks t]
["List cookies" url-cookie-list t]
+ ["Toggle fonts" eww-toggle-fonts t]
+ ["Toggle colors" eww-toggle-colors t]
["Character Encoding" eww-set-character-encoding]
["Toggle Paragraph Direction" eww-toggle-paragraph-direction]))
map))
@@ -1516,6 +1549,24 @@ If CHARSET is nil then use UTF-8."
(eww-reload nil 'utf-8)
(eww-reload nil charset)))
+(defun eww-switch-to-buffer ()
+ "Prompt for an EWW buffer to display in the selected window."
+ (interactive)
+ (let ((completion-extra-properties
+ '(:annotation-function (lambda (buf)
+ (with-current-buffer buf
+ (format " %s" (eww-current-url)))))))
+ (pop-to-buffer-same-window
+ (read-buffer "Switch to EWW buffer: "
+ (cl-loop for buf in (nreverse (buffer-list))
+ if (with-current-buffer buf (derived-mode-p 'eww-mode))
+ return buf)
+ t
+ (lambda (bufn)
+ (with-current-buffer
+ (if (consp bufn) (cdr bufn) (get-buffer bufn))
+ (derived-mode-p 'eww-mode)))))))
+
(defun eww-toggle-fonts ()
"Toggle whether to use monospaced or font-enabled layouts."
(interactive)
@@ -1524,6 +1575,15 @@ If CHARSET is nil then use UTF-8."
(message "Proportional fonts are now %s"
(if shr-use-fonts "on" "off")))
+(defun eww-toggle-colors ()
+ "Toggle whether to use HTML-specified colors or not."
+ (interactive)
+ (message "Colors are now %s"
+ (if (setq shr-use-colors (not shr-use-colors))
+ "on"
+ "off"))
+ (eww-reload))
+
;;; Bookmarks code
(defvar eww-bookmarks nil)
@@ -1964,7 +2024,7 @@ Otherwise, the restored buffer will contain a prompt to do so by using
(list :url (plist-get misc-data :uri))))
(unless file-name
(when (plist-get eww-data :url)
- (case eww-restore-desktop
+ (cl-case eww-restore-desktop
((t auto) (eww (plist-get eww-data :url)))
((zerop (buffer-size))
(let ((inhibit-read-only t))
diff --git a/lisp/net/gnutls.el b/lisp/net/gnutls.el
index ce44c032231..9ed1c8b8305 100644
--- a/lisp/net/gnutls.el
+++ b/lisp/net/gnutls.el
@@ -26,7 +26,7 @@
;; This package provides language bindings for the GnuTLS library
;; using the corresponding core functions in gnutls.c. It should NOT
-;; be used directly, only through open-protocol-stream.
+;; be used directly, only through open-network-stream.
;; Simple test:
;;
@@ -95,7 +95,7 @@ A value of nil says to use the default GnuTLS value."
(integer :tag "Number of bits" 512))
:group 'gnutls)
-(defun open-gnutls-stream (name buffer host service)
+(defun open-gnutls-stream (name buffer host service &optional nowait)
"Open a SSL/TLS connection for a service to a host.
Returns a subprocess-object to represent the connection.
Input and output work as for subprocesses; `delete-process' closes it.
@@ -109,6 +109,9 @@ BUFFER is the buffer (or `buffer-name') to associate with the process.
Third arg is name of the host to connect to, or its IP address.
Fourth arg SERVICE is name of the service desired, or an integer
specifying a port number to connect to.
+Fifth arg NOWAIT (which is optional) means that the socket should
+be opened asynchronously. The connection process will be
+returned to the caller before TLS negotiation has happened.
Usage example:
@@ -122,9 +125,20 @@ This is a very simple wrapper around `gnutls-negotiate'. See its
documentation for the specific parameters you can use to open a
GnuTLS connection, including specifying the credential type,
trust and key files, and priority string."
- (gnutls-negotiate :process (open-network-stream name buffer host service)
- :type 'gnutls-x509pki
- :hostname host))
+ (let ((process (open-network-stream
+ name buffer host service
+ :nowait nowait
+ :tls-parameters
+ (and nowait
+ (cons 'gnutls-x509pki
+ (gnutls-boot-parameters
+ :type 'gnutls-x509pki
+ :hostname host))))))
+ (if nowait
+ process
+ (gnutls-negotiate :process process
+ :type 'gnutls-x509pki
+ :hostname host))))
(define-error 'gnutls-error "GnuTLS error")
@@ -140,10 +154,47 @@ trust and key files, and priority string."
&allow-other-keys)
"Negotiate a SSL/TLS connection. Returns proc. Signals gnutls-error.
-Note arguments are passed CL style, :type TYPE instead of just TYPE.
+Note that arguments are passed CL style, :type TYPE instead of just TYPE.
-TYPE is `gnutls-x509pki' (default) or `gnutls-anon'. Use nil for the default.
PROCESS is a process returned by `open-network-stream'.
+For the meaning of the rest of the parameters, see `gnutls-boot-parameters'."
+ (let* ((type (or type 'gnutls-x509pki))
+ ;; The gnutls library doesn't understand files delivered via
+ ;; the special handlers, so ignore all files found via those.
+ (file-name-handler-alist nil)
+ (params (gnutls-boot-parameters
+ :type type
+ :hostname hostname
+ :priority-string priority-string
+ :trustfiles trustfiles
+ :crlfiles crlfiles
+ :keylist keylist
+ :min-prime-bits min-prime-bits
+ :verify-flags verify-flags
+ :verify-error verify-error
+ :verify-hostname-error verify-hostname-error))
+ ret)
+ (gnutls-message-maybe
+ (setq ret (gnutls-boot process type
+ (append (list :complete-negotiation t)
+ params)))
+ "boot: %s" params)
+
+ (when (gnutls-errorp ret)
+ ;; This is a error from the underlying C code.
+ (signal 'gnutls-error (list process ret)))
+
+ process))
+
+(cl-defun gnutls-boot-parameters
+ (&rest spec
+ &key type hostname priority-string
+ trustfiles crlfiles keylist min-prime-bits
+ verify-flags verify-error verify-hostname-error
+ &allow-other-keys)
+ "Return a keyword list of parameters suitable for passing to `gnutls-boot'.
+
+TYPE is `gnutls-x509pki' (default) or `gnutls-anon'. Use nil for the default.
HOSTNAME is the remote hostname. It must be a valid string.
PRIORITY-STRING is as per the GnuTLS docs, default is \"NORMAL\".
TRUSTFILES is a list of CA bundles. It defaults to `gnutls-trustfiles'.
@@ -189,62 +240,47 @@ here's a recent version of the list.
It must be omitted, a number, or nil; if omitted or nil it
defaults to GNUTLS_VERIFY_ALLOW_X509_V1_CA_CRT."
- (let* ((type (or type 'gnutls-x509pki))
- ;; The gnutls library doesn't understand files delivered via
- ;; the special handlers, so ignore all files found via those.
- (file-name-handler-alist nil)
- (trustfiles (or trustfiles (gnutls-trustfiles)))
- (priority-string (or priority-string
- (cond
- ((eq type 'gnutls-anon)
- "NORMAL:+ANON-DH:!ARCFOUR-128")
- ((eq type 'gnutls-x509pki)
- (if gnutls-algorithm-priority
- (upcase gnutls-algorithm-priority)
- "NORMAL")))))
- (verify-error (or verify-error
- ;; this uses the value of `gnutls-verify-error'
- (cond
- ;; if t, pass it on
- ((eq gnutls-verify-error t)
- t)
- ;; if a list, look for hostname matches
- ((listp gnutls-verify-error)
- (apply 'append
- (mapcar
- (lambda (check)
- (when (string-match (nth 0 check)
- hostname)
- (nth 1 check)))
- gnutls-verify-error)))
- ;; else it's nil
- (t nil))))
- (min-prime-bits (or min-prime-bits gnutls-min-prime-bits))
- params ret)
+ (let ((trustfiles (or trustfiles (gnutls-trustfiles)))
+ (priority-string (or priority-string
+ (cond
+ ((eq type 'gnutls-anon)
+ "NORMAL:+ANON-DH:!ARCFOUR-128")
+ ((eq type 'gnutls-x509pki)
+ (if gnutls-algorithm-priority
+ (upcase gnutls-algorithm-priority)
+ "NORMAL")))))
+ (verify-error (or verify-error
+ ;; this uses the value of `gnutls-verify-error'
+ (cond
+ ;; if t, pass it on
+ ((eq gnutls-verify-error t)
+ t)
+ ;; if a list, look for hostname matches
+ ((listp gnutls-verify-error)
+ (apply 'append
+ (mapcar
+ (lambda (check)
+ (when (string-match (nth 0 check)
+ hostname)
+ (nth 1 check)))
+ gnutls-verify-error)))
+ ;; else it's nil
+ (t nil))))
+ (min-prime-bits (or min-prime-bits gnutls-min-prime-bits)))
(when verify-hostname-error
(push :hostname verify-error))
- (setq params `(:priority ,priority-string
- :hostname ,hostname
- :loglevel ,gnutls-log-level
- :min-prime-bits ,min-prime-bits
- :trustfiles ,trustfiles
- :crlfiles ,crlfiles
- :keylist ,keylist
- :verify-flags ,verify-flags
- :verify-error ,verify-error
- :callbacks nil))
-
- (gnutls-message-maybe
- (setq ret (gnutls-boot process type params))
- "boot: %s" params)
-
- (when (gnutls-errorp ret)
- ;; This is a error from the underlying C code.
- (signal 'gnutls-error (list process ret)))
-
- process))
+ `(:priority ,priority-string
+ :hostname ,hostname
+ :loglevel ,gnutls-log-level
+ :min-prime-bits ,min-prime-bits
+ :trustfiles ,trustfiles
+ :crlfiles ,crlfiles
+ :keylist ,keylist
+ :verify-flags ,verify-flags
+ :verify-error ,verify-error
+ :callbacks nil)))
(defun gnutls-trustfiles ()
"Return a list of usable trustfiles."
diff --git a/lisp/net/html2text.el b/lisp/net/html2text.el
new file mode 100644
index 00000000000..2b1c2057bb4
--- /dev/null
+++ b/lisp/net/html2text.el
@@ -0,0 +1,461 @@
+;;; html2text.el --- a simple html to plain text converter -*- coding: utf-8 -*-
+
+;; Copyright (C) 2002-2016 Free Software Foundation, Inc.
+
+;; Author: Joakim Hove <hove@phys.ntnu.no>
+
+;; 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 3 of the License, 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. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; These functions provide a simple way to wash/clean html infected
+;; mails. Definitely do not work in all cases, but some improvement
+;; in readability is generally obtained. Formatting is only done in
+;; the buffer, so the next time you enter the article it will be
+;; "re-htmlized".
+;;
+;; The main function is `html2text'.
+
+;;; Code:
+
+;;
+;; <Global variables>
+;;
+
+(eval-when-compile
+ (require 'cl))
+
+(defvar html2text-format-single-element-list '(("hr" . html2text-clean-hr)))
+
+(defvar html2text-replace-list
+ '(("&acute;" . "`")
+ ("&amp;" . "&")
+ ("&apos;" . "'")
+ ("&brvbar;" . "|")
+ ("&cent;" . "c")
+ ("&circ;" . "^")
+ ("&copy;" . "(C)")
+ ("&curren;" . "(#)")
+ ("&deg;" . "degree")
+ ("&divide;" . "/")
+ ("&euro;" . "e")
+ ("&frac12;" . "1/2")
+ ("&gt;" . ">")
+ ("&iquest;" . "?")
+ ("&laquo;" . "<<")
+ ("&ldquo" . "\"")
+ ("&lsaquo;" . "(")
+ ("&lsquo;" . "`")
+ ("&lt;" . "<")
+ ("&mdash;" . "--")
+ ("&nbsp;" . " ")
+ ("&ndash;" . "-")
+ ("&permil;" . "%%")
+ ("&plusmn;" . "+-")
+ ("&pound;" . "£")
+ ("&quot;" . "\"")
+ ("&raquo;" . ">>")
+ ("&rdquo" . "\"")
+ ("&reg;" . "(R)")
+ ("&rsaquo;" . ")")
+ ("&rsquo;" . "'")
+ ("&sect;" . "§")
+ ("&sup1;" . "^1")
+ ("&sup2;" . "^2")
+ ("&sup3;" . "^3")
+ ("&tilde;" . "~"))
+ "The map of entity to text.
+
+This is an alist were each element is a dotted pair consisting of an
+old string, and a replacement string. This replacement is done by the
+function `html2text-substitute' which basically performs a
+`replace-string' operation for every element in the list. This is
+completely verbatim - without any use of REGEXP.")
+
+(defvar html2text-remove-tag-list
+ '("html" "body" "p" "img" "dir" "head" "div" "br" "font" "title" "meta")
+ "A list of removable tags.
+
+This is a list of tags which should be removed, without any
+formatting. Note that tags in the list are presented *without*
+any \"<\" or \">\". All occurrences of a tag appearing in this
+list are removed, irrespective of whether it is a closing or
+opening tag, or if the tag has additional attributes. The
+deletion is done by the function `html2text-remove-tags'.
+
+For instance the text:
+
+\"Here comes something <font size\"+3\" face=\"Helvetica\"> big </font>.\"
+
+will be reduced to:
+
+\"Here comes something big.\"
+
+If this list contains the element \"font\".")
+
+(defvar html2text-format-tag-list
+ '(("b" . html2text-clean-bold)
+ ("strong" . html2text-clean-bold)
+ ("u" . html2text-clean-underline)
+ ("i" . html2text-clean-italic)
+ ("em" . html2text-clean-italic)
+ ("blockquote" . html2text-clean-blockquote)
+ ("a" . html2text-clean-anchor)
+ ("ul" . html2text-clean-ul)
+ ("ol" . html2text-clean-ol)
+ ("dl" . html2text-clean-dl)
+ ("center" . html2text-clean-center))
+ "An alist of tags and processing functions.
+
+This is an alist where each dotted pair consists of a tag, and then
+the name of a function to be called when this tag is found. The
+function is called with the arguments p1, p2, p3 and p4. These are
+demonstrated below:
+
+\"<b> This is bold text </b>\"
+ ^ ^ ^ ^
+ | | | |
+p1 p2 p3 p4
+
+Then the called function will typically format the text somewhat and
+remove the tags.")
+
+(defvar html2text-remove-tag-list2 '("li" "dt" "dd" "meta")
+ "Another list of removable tags.
+
+This is a list of tags which are removed similarly to the list
+`html2text-remove-tag-list' - but these tags are retained for the
+formatting, and then moved afterward.")
+
+;;
+;; </Global variables>
+;;
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;;
+;; <Utility functions>
+;;
+
+
+(defun html2text-replace-string (from-string to-string min max)
+ "Replace FROM-STRING with TO-STRING in region from MIN to MAX."
+ (goto-char min)
+ (let ((delta (- (string-width to-string) (string-width from-string)))
+ (change 0))
+ (while (search-forward from-string max t)
+ (replace-match to-string)
+ (setq change (+ change delta)))
+ change))
+
+;;
+;; </Utility functions>
+;;
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;;
+;; <Functions related to attributes> i.e. <font size=+3>
+;;
+
+(defun html2text-attr-value (list attribute)
+ "Get value of ATTRIBUTE from LIST."
+ (nth 1 (assoc attribute list)))
+
+(defun html2text-get-attr (p1 p2)
+ (goto-char p1)
+ (re-search-forward "\\s-+" p2 t)
+ (let (attr-list)
+ (while (re-search-forward "[-a-z0-9._]+" p2 t)
+ (setq attr-list
+ (cons
+ (list (match-string 0)
+ (when (looking-at "\\s-*=")
+ (goto-char (match-end 0))
+ (skip-chars-forward "[:space:]")
+ (when (or (looking-at "\"[^\"]*\"\\|'[^']*'")
+ (looking-at "[-a-z0-9._:]+"))
+ (goto-char (match-end 0))
+ (match-string 0))))
+ attr-list)))
+ attr-list))
+
+;;
+;; </Functions related to attributes>
+;;
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;;
+;; <Functions to be called to format a tag-pair>
+;;
+(defun html2text-clean-list-items (p1 p2 list-type)
+ (goto-char p1)
+ (let ((item-nr 0)
+ (items 0))
+ (while (search-forward "<li>" p2 t)
+ (setq items (1+ items)))
+ (goto-char p1)
+ (while (< item-nr items)
+ (setq item-nr (1+ item-nr))
+ (search-forward "<li>" (point-max) t)
+ (cond
+ ((string= list-type "ul") (insert " o "))
+ ((string= list-type "ol") (insert (format " %s: " item-nr)))
+ (t (insert " x "))))))
+
+(defun html2text-clean-dtdd (p1 p2)
+ (goto-char p1)
+ (let ((items 0)
+ (item-nr 0))
+ (while (search-forward "<dt>" p2 t)
+ (setq items (1+ items)))
+ (goto-char p1)
+ (while (< item-nr items)
+ (setq item-nr (1+ item-nr))
+ (re-search-forward "<dt>\\([ ]*\\)" (point-max) t)
+ (when (match-string 1)
+ (delete-region (point) (- (point) (string-width (match-string 1)))))
+ (let ((def-p1 (point))
+ (def-p2 0))
+ (re-search-forward "\\([ ]*\\)\\(</dt>\\|<dd>\\)" (point-max) t)
+ (if (match-string 1)
+ (progn
+ (let* ((mw1 (string-width (match-string 1)))
+ (mw2 (string-width (match-string 2)))
+ (mw (+ mw1 mw2)))
+ (goto-char (- (point) mw))
+ (delete-region (point) (+ (point) mw1))
+ (setq def-p2 (point))))
+ (setq def-p2 (- (point) (string-width (match-string 2)))))
+ (put-text-property def-p1 def-p2 'face 'bold)))))
+
+(defun html2text-delete-tags (p1 p2 p3 p4)
+ (delete-region p1 p2)
+ (delete-region (- p3 (- p2 p1)) (- p4 (- p2 p1))))
+
+(defun html2text-delete-single-tag (p1 p2)
+ (delete-region p1 p2))
+
+(defun html2text-clean-hr (p1 p2)
+ (html2text-delete-single-tag p1 p2)
+ (goto-char p1)
+ (newline 1)
+ (insert (make-string fill-column ?-)))
+
+(defun html2text-clean-ul (p1 p2 p3 p4)
+ (html2text-delete-tags p1 p2 p3 p4)
+ (html2text-clean-list-items p1 (- p3 (- p1 p2)) "ul"))
+
+(defun html2text-clean-ol (p1 p2 p3 p4)
+ (html2text-delete-tags p1 p2 p3 p4)
+ (html2text-clean-list-items p1 (- p3 (- p1 p2)) "ol"))
+
+(defun html2text-clean-dl (p1 p2 p3 p4)
+ (html2text-delete-tags p1 p2 p3 p4)
+ (html2text-clean-dtdd p1 (- p3 (- p1 p2))))
+
+(defun html2text-clean-center (p1 p2 p3 p4)
+ (html2text-delete-tags p1 p2 p3 p4)
+ (center-region p1 (- p3 (- p2 p1))))
+
+(defun html2text-clean-bold (p1 p2 p3 p4)
+ (put-text-property p2 p3 'face 'bold)
+ (html2text-delete-tags p1 p2 p3 p4))
+
+(defun html2text-clean-title (p1 p2 p3 p4)
+ (put-text-property p2 p3 'face 'bold)
+ (html2text-delete-tags p1 p2 p3 p4))
+
+(defun html2text-clean-underline (p1 p2 p3 p4)
+ (put-text-property p2 p3 'face 'underline)
+ (html2text-delete-tags p1 p2 p3 p4))
+
+(defun html2text-clean-italic (p1 p2 p3 p4)
+ (put-text-property p2 p3 'face 'italic)
+ (html2text-delete-tags p1 p2 p3 p4))
+
+(defun html2text-clean-font (p1 p2 p3 p4)
+ (html2text-delete-tags p1 p2 p3 p4))
+
+(defun html2text-clean-blockquote (p1 p2 p3 p4)
+ (html2text-delete-tags p1 p2 p3 p4))
+
+(defun html2text-clean-anchor (p1 p2 p3 p4)
+ ;; If someone can explain how to make the URL clickable I will surely
+ ;; improve upon this.
+ ;; Maybe `goto-addr.el' can be used here.
+ (let* ((attr-list (html2text-get-attr p1 p2))
+ (href (html2text-attr-value attr-list "href")))
+ (delete-region p1 p4)
+ (when href
+ (goto-char p1)
+ (insert (if (string-match "\\`['\"].*['\"]\\'" href)
+ (substring href 1 -1) href))
+ (put-text-property p1 (point) 'face 'bold))))
+
+;;
+;; </Functions to be called to format a tag-pair>
+;;
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;;
+;; <Functions to be called to fix up paragraphs>
+;;
+
+(defun html2text-fix-paragraph (p1 p2)
+ (goto-char p1)
+ (let ((refill-start)
+ (refill-stop))
+ (when (re-search-forward "<br>$" p2 t)
+ (goto-char p1)
+ (when (re-search-forward ".+[^<][^b][^r][^>]$" p2 t)
+ (beginning-of-line)
+ (setq refill-start (point))
+ (goto-char p2)
+ (re-search-backward ".+[^<][^b][^r][^>]$" refill-start t)
+ (forward-line 1)
+ (end-of-line)
+ ;; refill-stop should ideally be adjusted to
+ ;; accommodate the "<br>" strings which are removed
+ ;; between refill-start and refill-stop. Can simply
+ ;; be returned from my-replace-string
+ (setq refill-stop (+ (point)
+ (html2text-replace-string
+ "<br>" ""
+ refill-start (point))))
+ ;; (message "Point = %s refill-stop = %s" (point) refill-stop)
+ ;; (sleep-for 4)
+ (fill-region refill-start refill-stop))))
+ (html2text-replace-string "<br>" "" p1 p2))
+
+;;
+;; This one is interactive ...
+;;
+(defun html2text-fix-paragraphs ()
+ "This _tries_ to fix up the paragraphs - this is done in quite a ad-hook
+fashion, quite close to pure guess-work. It does work in some cases though."
+ (interactive)
+ (goto-char (point-min))
+ (while (re-search-forward "^<br>$" nil t)
+ (delete-region (match-beginning 0) (match-end 0)))
+ ;; Removing lonely <br> on a single line, if they are left intact we
+ ;; don't have any paragraphs at all.
+ (goto-char (point-min))
+ (while (not (eobp))
+ (let ((p1 (point)))
+ (forward-paragraph 1)
+ ;;(message "Kaller fix med p1=%s p2=%s " p1 (1- (point))) (sleep-for 5)
+ (html2text-fix-paragraph p1 (1- (point)))
+ (goto-char p1)
+ (when (not (eobp))
+ (forward-paragraph 1)))))
+
+;;
+;; </Functions to be called to fix up paragraphs>
+;;
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;;
+;; <Interactive functions>
+;;
+
+(defun html2text-remove-tags (tag-list)
+ "Removes the tags listed in the list `html2text-remove-tag-list'.
+See the documentation for that variable."
+ (interactive)
+ (dolist (tag tag-list)
+ (goto-char (point-min))
+ (while (re-search-forward (format "\\(</?%s[^>]*>\\)" tag) (point-max) t)
+ (delete-region (match-beginning 0) (match-end 0)))))
+
+(defun html2text-format-tags ()
+ "See the variable `html2text-format-tag-list' for documentation."
+ (interactive)
+ (dolist (tag-and-function html2text-format-tag-list)
+ (let ((tag (car tag-and-function))
+ (function (cdr tag-and-function)))
+ (goto-char (point-min))
+ (while (re-search-forward (format "\\(<%s\\( [^>]*\\)?>\\)" tag)
+ (point-max) t)
+ (let ((p1)
+ (p2 (point))
+ (p3) (p4))
+ (search-backward "<" (point-min) t)
+ (setq p1 (point))
+ (unless (search-forward (format "</%s>" tag) (point-max) t)
+ (goto-char p2)
+ (insert (format "</%s>" tag)))
+ (setq p4 (point))
+ (search-backward "</" (point-min) t)
+ (setq p3 (point))
+ (funcall function p1 p2 p3 p4)
+ (goto-char p1))))))
+
+(defun html2text-substitute ()
+ "See the variable `html2text-replace-list' for documentation."
+ (interactive)
+ (dolist (e html2text-replace-list)
+ (goto-char (point-min))
+ (let ((old-string (car e))
+ (new-string (cdr e)))
+ (html2text-replace-string old-string new-string (point-min) (point-max)))))
+
+(defun html2text-format-single-elements ()
+ (interactive)
+ (dolist (tag-and-function html2text-format-single-element-list)
+ (let ((tag (car tag-and-function))
+ (function (cdr tag-and-function)))
+ (goto-char (point-min))
+ (while (re-search-forward (format "\\(<%s\\( [^>]*\\)?>\\)" tag)
+ (point-max) t)
+ (let ((p1)
+ (p2 (point)))
+ (search-backward "<" (point-min) t)
+ (setq p1 (point))
+ (funcall function p1 p2))))))
+
+;;
+;; Main function
+;;
+
+;;;###autoload
+(defun html2text ()
+ "Convert HTML to plain text in the current buffer."
+ (interactive)
+ (save-excursion
+ (let ((case-fold-search t)
+ (buffer-read-only))
+ (html2text-remove-tags html2text-remove-tag-list)
+ (html2text-format-tags)
+ (html2text-remove-tags html2text-remove-tag-list2)
+ (html2text-substitute)
+ (html2text-format-single-elements)
+ (html2text-fix-paragraphs))))
+
+;;
+;; </Interactive functions>
+;;
+(provide 'html2text)
+
+;;; html2text.el ends here
diff --git a/lisp/net/mailcap.el b/lisp/net/mailcap.el
new file mode 100644
index 00000000000..f71d7ba6675
--- /dev/null
+++ b/lisp/net/mailcap.el
@@ -0,0 +1,1111 @@
+;;; mailcap.el --- MIME media types configuration
+
+;; Copyright (C) 1998-2016 Free Software Foundation, Inc.
+
+;; Author: William M. Perry <wmperry@aventail.com>
+;; Lars Magne Ingebrigtsen <larsi@gnus.org>
+;; Keywords: news, mail, multimedia
+
+;; 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 3 of the License, 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. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Provides configuration of MIME media types from directly from Lisp
+;; and via the usual mailcap mechanism (RFC 1524). Deals with
+;; mime.types similarly.
+
+;;; Code:
+
+(eval-when-compile (require 'cl-lib))
+(autoload 'mail-header-parse-content-type "mail-parse")
+
+(defgroup mailcap nil
+ "Definition of viewers for MIME types."
+ :version "21.1"
+ :group 'mime)
+
+(defvar mailcap-parse-args-syntax-table
+ (let ((table (copy-syntax-table emacs-lisp-mode-syntax-table)))
+ (modify-syntax-entry ?' "\"" table)
+ (modify-syntax-entry ?` "\"" table)
+ (modify-syntax-entry ?{ "(" table)
+ (modify-syntax-entry ?} ")" table)
+ table)
+ "A syntax table for parsing SGML attributes.")
+
+(defvar mailcap-print-command
+ (mapconcat 'identity
+ (cons (if (boundp 'lpr-command)
+ lpr-command
+ "lpr")
+ (when (boundp 'lpr-switches)
+ (if (stringp lpr-switches)
+ (list lpr-switches)
+ lpr-switches)))
+ " ")
+ "Shell command (including switches) used to print PostScript files.")
+
+(defun mailcap--get-user-mime-data (sym)
+ (let ((val (default-value sym))
+ res)
+ (dolist (entry val)
+ (push (list (cdr (assq 'viewer entry))
+ (cdr (assq 'type entry))
+ (cdr (assq 'test entry)))
+ res))
+ (nreverse res)))
+
+(defun mailcap--set-user-mime-data (sym val)
+ (let (res)
+ (dolist (entry val)
+ (push `((viewer . ,(car entry))
+ (type . ,(cadr entry))
+ ,@(when (cl-caddr entry)
+ `((test . ,(cl-caddr entry)))))
+ res))
+ (set-default sym (nreverse res))))
+
+(defcustom mailcap-user-mime-data nil
+ "A list of viewers preferred for different MIME types.
+The elements of the list are alists of the following structure
+
+ ((viewer . VIEWER)
+ (type . MIME-TYPE)
+ (test . TEST))
+
+where VIEWER is either a lisp command, e.g., a major-mode, or a
+string containing a shell command for viewing files of the
+defined MIME-TYPE. In case of a shell command, %s will be
+replaced with the file.
+
+MIME-TYPE is a regular expression being matched against the
+actual MIME type. It is implicitly surrounded with ^ and $.
+
+TEST is an lisp form which is evaluated in order to test if the
+entry should be chosen. The `test' entry is optional.
+
+When selecting a viewer for a given MIME type, the first viewer
+in this list with a matching MIME-TYPE and successful TEST is
+selected. Only if none matches, the standard `mailcap-mime-data'
+is consulted."
+ :type '(repeat
+ (list
+ (choice (function :tag "Function or mode")
+ (string :tag "Shell command"))
+ (regexp :tag "MIME Type")
+ (sexp :tag "Test (optional)")))
+ :get #'mailcap--get-user-mime-data
+ :set #'mailcap--set-user-mime-data
+ :group 'mailcap)
+
+;; Postpone using defcustom for this as it's so big and we essentially
+;; have to have two copies of the data around then. Perhaps just
+;; customize the Lisp viewers and rely on the normal configuration
+;; files for the rest? -- fx
+(defvar mailcap-mime-data
+ `(("application"
+ ("vnd\\.ms-excel"
+ (viewer . "gnumeric %s")
+ (test . (getenv "DISPLAY"))
+ (type . "application/vnd.ms-excel"))
+ ("x-x509-ca-cert"
+ (viewer . ssl-view-site-cert)
+ (type . "application/x-x509-ca-cert"))
+ ("x-x509-user-cert"
+ (viewer . ssl-view-user-cert)
+ (type . "application/x-x509-user-cert"))
+ ("octet-stream"
+ (viewer . mailcap-save-binary-file)
+ (non-viewer . t)
+ (type . "application/octet-stream"))
+ ("dvi"
+ (viewer . "xdvi -safer %s")
+ (test . (eq window-system 'x))
+ ("needsx11")
+ (type . "application/dvi")
+ ("print" . "dvips -qRP %s"))
+ ("dvi"
+ (viewer . "dvitty %s")
+ (test . (not (getenv "DISPLAY")))
+ (type . "application/dvi")
+ ("print" . "dvips -qRP %s"))
+ ("emacs-lisp"
+ (viewer . mailcap-maybe-eval)
+ (type . "application/emacs-lisp"))
+ ("x-emacs-lisp"
+ (viewer . mailcap-maybe-eval)
+ (type . "application/x-emacs-lisp"))
+ ("x-tar"
+ (viewer . mailcap-save-binary-file)
+ (non-viewer . t)
+ (type . "application/x-tar"))
+ ("x-latex"
+ (viewer . tex-mode)
+ (type . "application/x-latex"))
+ ("x-tex"
+ (viewer . tex-mode)
+ (type . "application/x-tex"))
+ ("latex"
+ (viewer . tex-mode)
+ (type . "application/latex"))
+ ("tex"
+ (viewer . tex-mode)
+ (type . "application/tex"))
+ ("texinfo"
+ (viewer . texinfo-mode)
+ (type . "application/tex"))
+ ("zip"
+ (viewer . mailcap-save-binary-file)
+ (non-viewer . t)
+ (type . "application/zip")
+ ("copiousoutput"))
+ ("pdf"
+ (viewer . pdf-view-mode)
+ (type . "application/pdf")
+ (test . (eq window-system 'x)))
+ ("pdf"
+ (viewer . doc-view-mode)
+ (type . "application/pdf")
+ (test . (eq window-system 'x)))
+ ("pdf"
+ (viewer . "gv -safer %s")
+ (type . "application/pdf")
+ (test . window-system)
+ ("print" . ,(concat "pdf2ps %s - | " mailcap-print-command)))
+ ("pdf"
+ (viewer . "gpdf %s")
+ (type . "application/pdf")
+ ("print" . ,(concat "pdftops %s - | " mailcap-print-command))
+ (test . (eq window-system 'x)))
+ ("pdf"
+ (viewer . "xpdf %s")
+ (type . "application/pdf")
+ ("print" . ,(concat "pdftops %s - | " mailcap-print-command))
+ (test . (eq window-system 'x)))
+ ("pdf"
+ (viewer . ,(concat "pdftotext %s -"))
+ (type . "application/pdf")
+ ("print" . ,(concat "pdftops %s - | " mailcap-print-command))
+ ("copiousoutput"))
+ ("postscript"
+ (viewer . "gv -safer %s")
+ (type . "application/postscript")
+ (test . window-system)
+ ("print" . ,(concat mailcap-print-command " %s"))
+ ("needsx11"))
+ ("postscript"
+ (viewer . "ghostview -dSAFER %s")
+ (type . "application/postscript")
+ (test . (eq window-system 'x))
+ ("print" . ,(concat mailcap-print-command " %s"))
+ ("needsx11"))
+ ("postscript"
+ (viewer . "ps2ascii %s")
+ (type . "application/postscript")
+ (test . (not (getenv "DISPLAY")))
+ ("print" . ,(concat mailcap-print-command " %s"))
+ ("copiousoutput"))
+ ("sieve"
+ (viewer . sieve-mode)
+ (type . "application/sieve"))
+ ("pgp-keys"
+ (viewer . "gpg --import --interactive --verbose")
+ (type . "application/pgp-keys")
+ ("needsterminal")))
+ ("audio"
+ ("x-mpeg"
+ (viewer . "maplay %s")
+ (type . "audio/x-mpeg"))
+ (".*"
+ (viewer . "showaudio")
+ (type . "audio/*")))
+ ("message"
+ ("rfc-*822"
+ (viewer . mm-view-message)
+ (test . (and (featurep 'gnus)
+ (gnus-alive-p)))
+ (type . "message/rfc822"))
+ ("rfc-*822"
+ (viewer . vm-mode)
+ (type . "message/rfc822"))
+ ("rfc-*822"
+ (viewer . view-mode)
+ (type . "message/rfc822")))
+ ("image"
+ ("x-xwd"
+ (viewer . "xwud -in %s")
+ (type . "image/x-xwd")
+ ("compose" . "xwd -frame > %s")
+ (test . (eq window-system 'x))
+ ("needsx11"))
+ ("x11-dump"
+ (viewer . "xwud -in %s")
+ (type . "image/x-xwd")
+ ("compose" . "xwd -frame > %s")
+ (test . (eq window-system 'x))
+ ("needsx11"))
+ ("windowdump"
+ (viewer . "xwud -in %s")
+ (type . "image/x-xwd")
+ ("compose" . "xwd -frame > %s")
+ (test . (eq window-system 'x))
+ ("needsx11"))
+ (".*"
+ (viewer . "display %s")
+ (type . "image/*")
+ (test . (eq window-system 'x))
+ ("needsx11"))
+ (".*"
+ (viewer . "ee %s")
+ (type . "image/*")
+ (test . (eq window-system 'x))
+ ("needsx11")))
+ ("text"
+ ("plain"
+ (viewer . view-mode)
+ (type . "text/plain"))
+ ("plain"
+ (viewer . fundamental-mode)
+ (type . "text/plain"))
+ ("enriched"
+ (viewer . enriched-decode)
+ (type . "text/enriched"))
+ ("dns"
+ (viewer . dns-mode)
+ (type . "text/dns")))
+ ("video"
+ ("mpeg"
+ (viewer . "mpeg_play %s")
+ (type . "video/mpeg")
+ (test . (eq window-system 'x))
+ ("needsx11")))
+ ("x-world"
+ ("x-vrml"
+ (viewer . "webspace -remote %s -URL %u")
+ (type . "x-world/x-vrml")
+ ("description"
+ "VRML document")))
+ ("archive"
+ ("tar"
+ (viewer . tar-mode)
+ (type . "archive/tar"))))
+ "The mailcap structure is an assoc list of assoc lists.
+1st assoc list is keyed on the major content-type
+2nd assoc list is keyed on the minor content-type (which can be a regexp)
+
+Which looks like:
+-----------------
+ ((\"application\"
+ (\"postscript\" . <info>))
+ (\"text\"
+ (\"plain\" . <info>)))
+
+Where <info> is another assoc list of the various information
+related to the mailcap RFC 1524. This is keyed on the lowercase
+attribute name (viewer, test, etc). This looks like:
+ ((viewer . VIEWERINFO)
+ (test . TESTINFO)
+ (xxxx . \"STRING\")
+ FLAG)
+
+Where VIEWERINFO specifies how the content-type is viewed. Can be
+a string, in which case it is run through a shell, with appropriate
+parameters, or a symbol, in which case the symbol is `funcall'ed if
+and only if it exists as a function, with the buffer as an argument.
+
+TESTINFO is a test for the viewer's applicability, or nil. If nil, it
+means the viewer is always valid. If it is a Lisp function, it is
+called with a list of items from any extra fields from the
+Content-Type header as argument to return a boolean value for the
+validity. Otherwise, if it is a non-function Lisp symbol or list
+whose car is a symbol, it is `eval'led to yield the validity. If it
+is a string or list of strings, it represents a shell command to run
+to return a true or false shell value for the validity.")
+(put 'mailcap-mime-data 'risky-local-variable t)
+
+(defcustom mailcap-download-directory nil
+ "Directory to which `mailcap-save-binary-file' downloads files by default.
+nil means your home directory."
+ :type '(choice (const :tag "Home directory" nil)
+ directory)
+ :group 'mailcap)
+
+(defvar mailcap-poor-system-types
+ '(ms-dos windows-nt)
+ "Systems that don't have a Unix-like directory hierarchy.")
+
+;;;
+;;; Utility functions
+;;;
+
+(defun mailcap-save-binary-file ()
+ (goto-char (point-min))
+ (unwind-protect
+ (let ((file (read-file-name
+ "Filename to save as: "
+ (or mailcap-download-directory "~/")))
+ (require-final-newline nil))
+ (write-region (point-min) (point-max) file))
+ (kill-buffer (current-buffer))))
+
+(defvar mailcap-maybe-eval-warning
+ "*** WARNING ***
+
+This MIME part contains untrusted and possibly harmful content.
+If you evaluate the Emacs Lisp code contained in it, a lot of nasty
+things can happen. Please examine the code very carefully before you
+instruct Emacs to evaluate it. You can browse the buffer containing
+the code using \\[scroll-other-window].
+
+If you are unsure what to do, please answer \"no\"."
+ "Text of warning message displayed by `mailcap-maybe-eval'.
+Make sure that this text consists only of few text lines. Otherwise,
+Gnus might fail to display all of it.")
+
+(defun mailcap-maybe-eval ()
+ "Maybe evaluate a buffer of Emacs Lisp code."
+ (let ((lisp-buffer (current-buffer)))
+ (goto-char (point-min))
+ (when
+ (save-window-excursion
+ (delete-other-windows)
+ (let ((buffer (get-buffer-create (generate-new-buffer-name
+ "*Warning*"))))
+ (unwind-protect
+ (with-current-buffer buffer
+ (insert (substitute-command-keys
+ mailcap-maybe-eval-warning))
+ (goto-char (point-min))
+ (display-buffer buffer)
+ (yes-or-no-p "This is potentially dangerous emacs-lisp code, evaluate it? "))
+ (kill-buffer buffer))))
+ (eval-buffer (current-buffer)))
+ (when (buffer-live-p lisp-buffer)
+ (with-current-buffer lisp-buffer
+ (emacs-lisp-mode)))))
+
+
+;;;
+;;; The mailcap parser
+;;;
+
+(defun mailcap-replace-regexp (regexp to-string)
+ ;; Quiet replace-regexp.
+ (goto-char (point-min))
+ (while (re-search-forward regexp nil t)
+ (replace-match to-string t nil)))
+
+(defvar mailcap-parsed-p nil)
+
+(defun mailcap-parse-mailcaps (&optional path force)
+ "Parse out all the mailcaps specified in a path string PATH.
+Components of PATH are separated by the `path-separator' character
+appropriate for this system. If FORCE, re-parse even if already
+parsed. If PATH is omitted, use the value of environment variable
+MAILCAPS if set; otherwise (on Unix) use the path from RFC 1524, plus
+/usr/local/etc/mailcap."
+ (interactive (list nil t))
+ (when (or (not mailcap-parsed-p)
+ force)
+ (cond
+ (path nil)
+ ((getenv "MAILCAPS") (setq path (getenv "MAILCAPS")))
+ ((memq system-type mailcap-poor-system-types)
+ (setq path '("~/.mailcap" "~/mail.cap" "~/etc/mail.cap")))
+ (t (setq path
+ ;; This is per RFC 1524, specifically
+ ;; with /usr before /usr/local.
+ '("~/.mailcap" "/etc/mailcap" "/usr/etc/mailcap"
+ "/usr/local/etc/mailcap"))))
+ (dolist (fname (reverse
+ (if (stringp path)
+ (split-string path path-separator t)
+ path)))
+ (if (and (file-readable-p fname)
+ (file-regular-p fname))
+ (mailcap-parse-mailcap fname)))
+ (setq mailcap-parsed-p t)))
+
+(defun mailcap-parse-mailcap (fname)
+ "Parse out the mailcap file specified by FNAME."
+ (let (major ; The major mime type (image/audio/etc)
+ minor ; The minor mime type (gif, basic, etc)
+ save-pos ; Misc saved positions used in parsing
+ viewer ; How to view this mime type
+ info ; Misc info about this mime type
+ )
+ (with-temp-buffer
+ (insert-file-contents fname)
+ (set-syntax-table mailcap-parse-args-syntax-table)
+ (mailcap-replace-regexp "#.*" "") ; Remove all comments
+ (mailcap-replace-regexp "\\\\[ \t]*\n" " ") ; And collapse spaces
+ (mailcap-replace-regexp "\n+" "\n") ; And blank lines
+ (goto-char (point-max))
+ (skip-chars-backward " \t\n")
+ (delete-region (point) (point-max))
+ (while (not (bobp))
+ (skip-chars-backward " \t\n")
+ (beginning-of-line)
+ (setq save-pos (point)
+ info nil)
+ (skip-chars-forward "^/; \t\n")
+ (downcase-region save-pos (point))
+ (setq major (buffer-substring save-pos (point)))
+ (skip-chars-forward " \t")
+ (setq minor "")
+ (when (eq (char-after) ?/)
+ (forward-char)
+ (skip-chars-forward " \t")
+ (setq save-pos (point))
+ (skip-chars-forward "^; \t\n")
+ (downcase-region save-pos (point))
+ (setq minor
+ (cond
+ ((eq ?* (or (char-after save-pos) 0)) ".*")
+ ((= (point) save-pos) ".*")
+ (t (regexp-quote (buffer-substring save-pos (point)))))))
+ (skip-chars-forward " \t")
+ ;;; Got the major/minor chunks, now for the viewers/etc
+ ;;; The first item _must_ be a viewer, according to the
+ ;;; RFC for mailcap files (#1524)
+ (setq viewer "")
+ (when (eq (char-after) ?\;)
+ (forward-char)
+ (skip-chars-forward " \t")
+ (setq save-pos (point))
+ (skip-chars-forward "^;\n")
+ ;; skip \;
+ (while (eq (char-before) ?\\)
+ (backward-delete-char 1)
+ (forward-char)
+ (skip-chars-forward "^;\n"))
+ (if (eq (or (char-after save-pos) 0) ?')
+ (setq viewer (progn
+ (narrow-to-region (1+ save-pos) (point))
+ (goto-char (point-min))
+ (prog1
+ (read (current-buffer))
+ (goto-char (point-max))
+ (widen))))
+ (setq viewer (buffer-substring save-pos (point)))))
+ (setq save-pos (point))
+ (end-of-line)
+ (unless (equal viewer "")
+ (setq info (nconc (list (cons 'viewer viewer)
+ (cons 'type (concat major "/"
+ (if (string= minor ".*")
+ "*" minor))))
+ (mailcap-parse-mailcap-extras save-pos (point))))
+ (mailcap-mailcap-entry-passes-test info)
+ (mailcap-add-mailcap-entry major minor info))
+ (beginning-of-line)))))
+
+(defun mailcap-parse-mailcap-extras (st nd)
+ "Grab all the extra stuff from a mailcap entry."
+ (let (
+ name ; From name=
+ value ; its value
+ results ; Assoc list of results
+ name-pos ; Start of XXXX= position
+ val-pos ; Start of value position
+ done ; Found end of \'d ;s?
+ )
+ (save-restriction
+ (narrow-to-region st nd)
+ (goto-char (point-min))
+ (skip-chars-forward " \n\t;")
+ (while (not (eobp))
+ (setq done nil)
+ (setq name-pos (point))
+ (skip-chars-forward "^ \n\t=;")
+ (downcase-region name-pos (point))
+ (setq name (buffer-substring name-pos (point)))
+ (skip-chars-forward " \t\n")
+ (if (not (eq (char-after (point)) ?=)) ; There is no value
+ (setq value t)
+ (skip-chars-forward " \t\n=")
+ (setq val-pos (point))
+ (if (memq (char-after val-pos) '(?\" ?'))
+ (progn
+ (setq val-pos (1+ val-pos))
+ (condition-case nil
+ (progn
+ (forward-sexp 1)
+ (backward-char 1))
+ (error (goto-char (point-max)))))
+ (while (not done)
+ (skip-chars-forward "^;")
+ (if (eq (char-after (1- (point))) ?\\ )
+ (progn
+ (subst-char-in-region (1- (point)) (point) ?\\ ? )
+ (skip-chars-forward ";"))
+ (setq done t))))
+ (setq value (buffer-substring val-pos (point))))
+ ;; `test' as symbol, others like "copiousoutput" and "needsx11" as
+ ;; strings
+ (push (cons (if (string-equal name "test") 'test name) value) results)
+ (skip-chars-forward " \";\n\t"))
+ results)))
+
+(defun mailcap-mailcap-entry-passes-test (info)
+ "Replace the test clause of INFO itself with a boolean for some cases.
+This function supports only `test -n $DISPLAY' and `test -z $DISPLAY',
+replaces them with t or nil. As for others or if INFO has a interactive
+spec (needsterm, needsterminal, or needsx11) but DISPLAY is not set,
+the test clause will be unchanged."
+ (let ((test (assq 'test info)) ; The test clause
+ status)
+ (setq status (and test (split-string (cdr test) " ")))
+ (if (and (or (assoc "needsterm" info)
+ (assoc "needsterminal" info)
+ (assoc "needsx11" info))
+ (not (getenv "DISPLAY")))
+ (setq status nil)
+ (cond
+ ((and (equal (nth 0 status) "test")
+ (equal (nth 1 status) "-n")
+ (or (equal (nth 2 status) "$DISPLAY")
+ (equal (nth 2 status) "\"$DISPLAY\"")))
+ (setq status (if (getenv "DISPLAY") t nil)))
+ ((and (equal (nth 0 status) "test")
+ (equal (nth 1 status) "-z")
+ (or (equal (nth 2 status) "$DISPLAY")
+ (equal (nth 2 status) "\"$DISPLAY\"")))
+ (setq status (if (getenv "DISPLAY") nil t)))
+ (test nil)
+ (t nil)))
+ (and test (listp test) (setcdr test status))))
+
+;;;
+;;; The action routines.
+;;;
+
+(defun mailcap-possible-viewers (major minor)
+ "Return a list of possible viewers from MAJOR for minor type MINOR."
+ (let ((exact '())
+ (wildcard '()))
+ (while major
+ (cond
+ ((equal (car (car major)) minor)
+ (push (cdr (car major)) exact))
+ ((and minor (string-match (concat "^" (car (car major)) "$") minor))
+ (push (cdr (car major)) wildcard)))
+ (setq major (cdr major)))
+ (nconc exact wildcard)))
+
+(defun mailcap-unescape-mime-test (test type-info)
+ (let (save-pos save-chr subst)
+ (cond
+ ((symbolp test) test)
+ ((and (listp test) (symbolp (car test))) test)
+ ((or (stringp test)
+ (and (listp test) (stringp (car test))
+ (setq test (mapconcat 'identity test " "))))
+ (with-temp-buffer
+ (insert test)
+ (goto-char (point-min))
+ (while (not (eobp))
+ (skip-chars-forward "^%")
+ (if (/= (- (point)
+ (progn (skip-chars-backward "\\\\")
+ (point)))
+ 0) ; It is an escaped %
+ (progn
+ (delete-char 1)
+ (skip-chars-forward "%."))
+ (setq save-pos (point))
+ (skip-chars-forward "%")
+ (setq save-chr (char-after (point)))
+ ;; Escapes:
+ ;; %s: name of a file for the body data
+ ;; %t: content-type
+ ;; %{<parameter name}: value of parameter in mailcap entry
+ ;; %n: number of sub-parts for multipart content-type
+ ;; %F: a set of content-type/filename pairs for multiparts
+ (cond
+ ((null save-chr) nil)
+ ((= save-chr ?t)
+ (delete-region save-pos (progn (forward-char 1) (point)))
+ (insert (or (cdr (assq 'type type-info)) "\"\"")))
+ ((memq save-chr '(?M ?n ?F))
+ (delete-region save-pos (progn (forward-char 1) (point)))
+ (insert "\"\""))
+ ((= save-chr ?{)
+ (forward-char 1)
+ (skip-chars-forward "^}")
+ (downcase-region (+ 2 save-pos) (point))
+ (setq subst (buffer-substring (+ 2 save-pos) (point)))
+ (delete-region save-pos (1+ (point)))
+ (insert (or (cdr (assoc subst type-info)) "\"\"")))
+ (t nil))))
+ (buffer-string)))
+ (t (error "Bad value to mailcap-unescape-mime-test: %s" test)))))
+
+(defvar mailcap-viewer-test-cache nil)
+
+(defun mailcap-viewer-passes-test (viewer-info type-info)
+ "Return non-nil if viewer specified by VIEWER-INFO passes its test clause.
+Also return non-nil if it has no test clause. TYPE-INFO is an argument
+to supply to the test."
+ (let* ((test-info (assq 'test viewer-info))
+ (test (cdr test-info))
+ (otest test)
+ (viewer (cdr (assq 'viewer viewer-info)))
+ (default-directory (expand-file-name "~/"))
+ status cache result)
+ (cond ((not (or (stringp viewer) (fboundp viewer)))
+ nil) ; Non-existent Lisp function
+ ((setq cache (assoc test mailcap-viewer-test-cache))
+ (cadr cache))
+ ((not test-info) t) ; No test clause
+ (t
+ (setq
+ result
+ (cond
+ ((not test) nil) ; Already failed test
+ ((eq test t) t) ; Already passed test
+ ((functionp test) ; Lisp function as test
+ (funcall test type-info))
+ ((and (symbolp test) ; Lisp variable as test
+ (boundp test))
+ (symbol-value test))
+ ((and (listp test) ; List to be eval'd
+ (symbolp (car test)))
+ (eval test))
+ (t
+ (setq test (mailcap-unescape-mime-test test type-info)
+ test (list shell-file-name nil nil nil
+ shell-command-switch test)
+ status (apply 'call-process test))
+ (eq 0 status))))
+ (push (list otest result) mailcap-viewer-test-cache)
+ result))))
+
+(defun mailcap-add-mailcap-entry (major minor info)
+ (let ((old-major (assoc major mailcap-mime-data)))
+ (if (null old-major) ; New major area
+ (push (cons major (list (cons minor info))) mailcap-mime-data)
+ (let ((cur-minor (assoc minor old-major)))
+ (cond
+ ((or (null cur-minor) ; New minor area, or
+ (assq 'test info)) ; Has a test, insert at beginning
+ (setcdr old-major (cons (cons minor info) (cdr old-major))))
+ ((and (not (assq 'test info)) ; No test info, replace completely
+ (not (assq 'test cur-minor))
+ (equal (assq 'viewer info) ; Keep alternative viewer
+ (assq 'viewer cur-minor)))
+ (setcdr cur-minor info))
+ (t
+ (setcdr old-major (cons (cons minor info) (cdr old-major))))))
+ )))
+
+(defun mailcap-add (type viewer &optional test)
+ "Add VIEWER as a handler for TYPE.
+If TEST is not given, it defaults to t."
+ (let ((tl (split-string type "/")))
+ (when (or (not (car tl))
+ (not (cadr tl)))
+ (error "%s is not a valid MIME type" type))
+ (mailcap-add-mailcap-entry
+ (car tl) (cadr tl)
+ `((viewer . ,viewer)
+ (test . ,(if test test t))
+ (type . ,type)))))
+
+;;;
+;;; The main whabbo
+;;;
+
+(defun mailcap-viewer-lessp (x y)
+ "Return t if viewer X is more desirable than viewer Y."
+ (let ((x-wild (string-match "[*?]" (or (cdr-safe (assq 'type x)) "")))
+ (y-wild (string-match "[*?]" (or (cdr-safe (assq 'type y)) "")))
+ (x-lisp (not (stringp (or (cdr-safe (assq 'viewer x)) ""))))
+ (y-lisp (not (stringp (or (cdr-safe (assq 'viewer y)) "")))))
+ (cond
+ ((and x-wild (not y-wild))
+ nil)
+ ((and (not x-wild) y-wild)
+ t)
+ ((and (not y-lisp) x-lisp)
+ t)
+ (t nil))))
+
+(defun mailcap-select-preferred-viewer (type-info)
+ "Return an applicable viewer entry from `mailcap-user-mime-data'."
+ (let ((info (mapcar (lambda (a) (cons (symbol-name (car a))
+ (cdr a)))
+ (cdr type-info)))
+ viewer)
+ (dolist (entry mailcap-user-mime-data)
+ (when (and (null viewer)
+ (string-match (concat "^" (cdr (assq 'type entry)) "$")
+ (car type-info))
+ (mailcap-viewer-passes-test entry info))
+ (setq viewer entry)))
+ viewer))
+
+(defun mailcap-mime-info (string &optional request no-decode)
+ "Get the MIME viewer command for STRING, return nil if none found.
+Expects a complete content-type header line as its argument.
+
+Second argument REQUEST specifies what information to return. If it is
+nil or the empty string, the viewer (second field of the mailcap
+entry) will be returned. If it is a string, then the mailcap field
+corresponding to that string will be returned (print, description,
+whatever). If a number, then all the information for this specific
+viewer is returned. If `all', then all possible viewers for
+this type is returned.
+
+If NO-DECODE is non-nil, don't decode STRING."
+ ;; NO-DECODE avoids calling `mail-header-parse-content-type' from
+ ;; `mail-parse.el'
+ (let (
+ major ; Major encoding (text, etc)
+ minor ; Minor encoding (html, etc)
+ info ; Other info
+ major-info ; (assoc major mailcap-mime-data)
+ viewers ; Possible viewers
+ passed ; Viewers that passed the test
+ viewer ; The one and only viewer
+ ctl)
+ (save-excursion
+ (setq ctl
+ (if no-decode
+ (list (or string "text/plain"))
+ (mail-header-parse-content-type (or string "text/plain"))))
+ ;; Check if there's a user-defined viewer from `mailcap-user-mime-data'.
+ (setq viewer (mailcap-select-preferred-viewer ctl))
+ (if viewer
+ (setq passed (list viewer))
+ ;; None found, so heuristically select some applicable viewer
+ ;; from `mailcap-mime-data'.
+ (setq major (split-string (car ctl) "/"))
+ (setq minor (cadr major)
+ major (car major))
+ (when (setq major-info (cdr (assoc major mailcap-mime-data)))
+ (when (setq viewers (mailcap-possible-viewers major-info minor))
+ (setq info (mapcar (lambda (a) (cons (symbol-name (car a))
+ (cdr a)))
+ (cdr ctl)))
+ (while viewers
+ (if (mailcap-viewer-passes-test (car viewers) info)
+ (push (car viewers) passed))
+ (setq viewers (cdr viewers)))
+ (setq passed (sort passed 'mailcap-viewer-lessp))
+ (setq viewer (car passed))))
+ (when (and (stringp (cdr (assq 'viewer viewer)))
+ passed)
+ (setq viewer (car passed))))
+ (cond
+ ((and (null viewer) (not (equal major "default")) request)
+ (mailcap-mime-info "default" request no-decode))
+ ((or (null request) (equal request ""))
+ (mailcap-unescape-mime-test (cdr (assq 'viewer viewer)) info))
+ ((stringp request)
+ (mailcap-unescape-mime-test
+ (cdr-safe (assoc request viewer)) info))
+ ((eq request 'all)
+ passed)
+ (t
+ ;; MUST make a copy *sigh*, else we modify mailcap-mime-data
+ (setq viewer (copy-sequence viewer))
+ (let ((view (assq 'viewer viewer))
+ (test (assq 'test viewer)))
+ (if view (setcdr view (mailcap-unescape-mime-test (cdr view) info)))
+ (if test (setcdr test (mailcap-unescape-mime-test (cdr test) info))))
+ viewer)))))
+
+;;;
+;;; Experimental MIME-types parsing
+;;;
+
+(defvar mailcap-mime-extensions
+ '(("" . "text/plain")
+ (".1" . "text/plain") ;; Manual pages
+ (".3" . "text/plain")
+ (".8" . "text/plain")
+ (".abs" . "audio/x-mpeg")
+ (".aif" . "audio/aiff")
+ (".aifc" . "audio/aiff")
+ (".aiff" . "audio/aiff")
+ (".ano" . "application/x-annotator")
+ (".au" . "audio/ulaw")
+ (".avi" . "video/x-msvideo")
+ (".bcpio" . "application/x-bcpio")
+ (".bin" . "application/octet-stream")
+ (".cdf" . "application/x-netcdr")
+ (".cpio" . "application/x-cpio")
+ (".csh" . "application/x-csh")
+ (".css" . "text/css")
+ (".dvi" . "application/x-dvi")
+ (".diff" . "text/x-patch")
+ (".dpatch". "test/x-patch")
+ (".el" . "application/emacs-lisp")
+ (".eps" . "application/postscript")
+ (".etx" . "text/x-setext")
+ (".exe" . "application/octet-stream")
+ (".fax" . "image/x-fax")
+ (".gif" . "image/gif")
+ (".hdf" . "application/x-hdf")
+ (".hqx" . "application/mac-binhex40")
+ (".htm" . "text/html")
+ (".html" . "text/html")
+ (".icon" . "image/x-icon")
+ (".ief" . "image/ief")
+ (".jpg" . "image/jpeg")
+ (".macp" . "image/x-macpaint")
+ (".man" . "application/x-troff-man")
+ (".me" . "application/x-troff-me")
+ (".mif" . "application/mif")
+ (".mov" . "video/quicktime")
+ (".movie" . "video/x-sgi-movie")
+ (".mp2" . "audio/x-mpeg")
+ (".mp3" . "audio/x-mpeg")
+ (".mp2a" . "audio/x-mpeg2")
+ (".mpa" . "audio/x-mpeg")
+ (".mpa2" . "audio/x-mpeg2")
+ (".mpe" . "video/mpeg")
+ (".mpeg" . "video/mpeg")
+ (".mpega" . "audio/x-mpeg")
+ (".mpegv" . "video/mpeg")
+ (".mpg" . "video/mpeg")
+ (".mpv" . "video/mpeg")
+ (".ms" . "application/x-troff-ms")
+ (".nc" . "application/x-netcdf")
+ (".nc" . "application/x-netcdf")
+ (".oda" . "application/oda")
+ (".patch" . "text/x-patch")
+ (".pbm" . "image/x-portable-bitmap")
+ (".pdf" . "application/pdf")
+ (".pgm" . "image/portable-graymap")
+ (".pict" . "image/pict")
+ (".png" . "image/png")
+ (".pnm" . "image/x-portable-anymap")
+ (".pod" . "text/plain")
+ (".ppm" . "image/portable-pixmap")
+ (".ps" . "application/postscript")
+ (".qt" . "video/quicktime")
+ (".ras" . "image/x-raster")
+ (".rgb" . "image/x-rgb")
+ (".rtf" . "application/rtf")
+ (".rtx" . "text/richtext")
+ (".sh" . "application/x-sh")
+ (".sit" . "application/x-stuffit")
+ (".siv" . "application/sieve")
+ (".snd" . "audio/basic")
+ (".soa" . "text/dns")
+ (".src" . "application/x-wais-source")
+ (".tar" . "archive/tar")
+ (".tcl" . "application/x-tcl")
+ (".tex" . "application/x-tex")
+ (".texi" . "application/texinfo")
+ (".tga" . "image/x-targa")
+ (".tif" . "image/tiff")
+ (".tiff" . "image/tiff")
+ (".tr" . "application/x-troff")
+ (".troff" . "application/x-troff")
+ (".tsv" . "text/tab-separated-values")
+ (".txt" . "text/plain")
+ (".vbs" . "video/mpeg")
+ (".vox" . "audio/basic")
+ (".vrml" . "x-world/x-vrml")
+ (".wav" . "audio/x-wav")
+ (".xls" . "application/vnd.ms-excel")
+ (".wrl" . "x-world/x-vrml")
+ (".xbm" . "image/xbm")
+ (".xpm" . "image/xpm")
+ (".xwd" . "image/windowdump")
+ (".zip" . "application/zip")
+ (".ai" . "application/postscript")
+ (".jpe" . "image/jpeg")
+ (".jpeg" . "image/jpeg")
+ (".org" . "text/x-org"))
+ "An alist of file extensions and corresponding MIME content-types.
+This exists for you to customize the information in Lisp. It is
+merged with values from mailcap files by `mailcap-parse-mimetypes'.")
+
+(defvar mailcap-mimetypes-parsed-p nil)
+
+(defun mailcap-parse-mimetypes (&optional path force)
+ "Parse out all the mimetypes specified in a Unix-style path string PATH.
+Components of PATH are separated by the `path-separator' character
+appropriate for this system. If PATH is omitted, use the value of
+environment variable MIMETYPES if set; otherwise use a default path.
+If FORCE, re-parse even if already parsed."
+ (interactive (list nil t))
+ (when (or (not mailcap-mimetypes-parsed-p)
+ force)
+ (cond
+ (path nil)
+ ((getenv "MIMETYPES") (setq path (getenv "MIMETYPES")))
+ ((memq system-type mailcap-poor-system-types)
+ (setq path '("~/mime.typ" "~/etc/mime.typ")))
+ (t (setq path
+ ;; mime.types seems to be the normal name, definitely so
+ ;; on current GNUish systems. The search order follows
+ ;; that for mailcap.
+ '("~/.mime.types"
+ "/etc/mime.types"
+ "/usr/etc/mime.types"
+ "/usr/local/etc/mime.types"
+ "/usr/local/www/conf/mime.types"
+ "~/.mime-types"
+ "/etc/mime-types"
+ "/usr/etc/mime-types"
+ "/usr/local/etc/mime-types"
+ "/usr/local/www/conf/mime-types"))))
+ (dolist (fname (reverse (if (stringp path)
+ (split-string path path-separator t)
+ path)))
+ (if (and (file-readable-p fname))
+ (mailcap-parse-mimetype-file fname)))
+ (setq mailcap-mimetypes-parsed-p t)))
+
+(defun mailcap-parse-mimetype-file (fname)
+ "Parse out a mime-types file FNAME."
+ (let (type ; The MIME type for this line
+ extns ; The extensions for this line
+ save-pos ; Misc. saved buffer positions
+ )
+ (with-temp-buffer
+ (insert-file-contents fname)
+ (mailcap-replace-regexp "#.*" "")
+ (mailcap-replace-regexp "\n+" "\n")
+ (mailcap-replace-regexp "[ \t]+$" "")
+ (goto-char (point-max))
+ (skip-chars-backward " \t\n")
+ (delete-region (point) (point-max))
+ (goto-char (point-min))
+ (while (not (eobp))
+ (skip-chars-forward " \t\n")
+ (setq save-pos (point))
+ (skip-chars-forward "^ \t\n")
+ (downcase-region save-pos (point))
+ (setq type (buffer-substring save-pos (point)))
+ (while (not (eolp))
+ (skip-chars-forward " \t")
+ (setq save-pos (point))
+ (skip-chars-forward "^ \t\n")
+ (setq extns (cons (buffer-substring save-pos (point)) extns)))
+ (while extns
+ (setq mailcap-mime-extensions
+ (cons
+ (cons (if (= (string-to-char (car extns)) ?.)
+ (car extns)
+ (concat "." (car extns))) type)
+ mailcap-mime-extensions)
+ extns (cdr extns)))))))
+
+(defun mailcap-extension-to-mime (extn)
+ "Return the MIME content type of the file extensions EXTN."
+ (mailcap-parse-mimetypes)
+ (if (and (stringp extn)
+ (not (eq (string-to-char extn) ?.)))
+ (setq extn (concat "." extn)))
+ (cdr (assoc (downcase extn) mailcap-mime-extensions)))
+
+;; Unused?
+(defalias 'mailcap-command-p 'executable-find)
+
+(defun mailcap-mime-types ()
+ "Return a list of MIME media types."
+ (mailcap-parse-mimetypes)
+ (delete-dups
+ (nconc
+ (mapcar 'cdr mailcap-mime-extensions)
+ (apply
+ 'nconc
+ (mapcar
+ (lambda (l)
+ (delq nil
+ (mapcar
+ (lambda (m)
+ (let ((type (cdr (assq 'type (cdr m)))))
+ (if (equal (cadr (split-string type "/"))
+ "*")
+ nil
+ type)))
+ (cdr l))))
+ mailcap-mime-data)))))
+
+;;;
+;;; Useful supplementary functions
+;;;
+
+(defun mailcap-file-default-commands (files)
+ "Return a list of default commands for FILES."
+ (mailcap-parse-mailcaps)
+ (mailcap-parse-mimetypes)
+ (let* ((all-mime-type
+ ;; All unique MIME types from file extensions
+ (delete-dups
+ (mapcar (lambda (file)
+ (mailcap-extension-to-mime
+ (file-name-extension file t)))
+ files)))
+ (all-mime-info
+ ;; All MIME info lists
+ (delete-dups
+ (mapcar (lambda (mime-type)
+ (mailcap-mime-info mime-type 'all))
+ all-mime-type)))
+ (common-mime-info
+ ;; Intersection of mime-infos from different mime-types;
+ ;; or just the first MIME info for a single MIME type
+ (if (cdr all-mime-info)
+ (delq nil (mapcar (lambda (mi1)
+ (unless (memq nil (mapcar
+ (lambda (mi2)
+ (member mi1 mi2))
+ (cdr all-mime-info)))
+ mi1))
+ (car all-mime-info)))
+ (car all-mime-info)))
+ (commands
+ ;; Command strings from `viewer' field of the MIME info
+ (delete-dups
+ (delq nil (mapcar
+ (lambda (mime-info)
+ (let ((command (cdr (assoc 'viewer mime-info))))
+ (if (stringp command)
+ (replace-regexp-in-string
+ ;; Replace mailcap's `%s' placeholder
+ ;; with dired's `?' placeholder
+ "%s" "?"
+ (replace-regexp-in-string
+ ;; Remove the final filename placeholder
+ "[ \t\n]*\\('\\)?%s\\1?[ \t\n]*\\'" ""
+ command nil t)
+ nil t))))
+ common-mime-info)))))
+ commands))
+
+(defun mailcap-view-mime (type)
+ "View the data in the current buffer that has MIME type TYPE.
+`mailcap-mime-data' determines the method to use."
+ (let ((method (mailcap-mime-info type)))
+ (if (stringp method)
+ (shell-command-on-region (point-min) (point-max)
+ ;; Use stdin as the "%s".
+ (format method "-")
+ (current-buffer)
+ t)
+ (funcall method))))
+
+(provide 'mailcap)
+
+;;; mailcap.el ends here
diff --git a/lisp/net/net-utils.el b/lisp/net/net-utils.el
index 8029e2ca70a..73d6ff4d61c 100644
--- a/lisp/net/net-utils.el
+++ b/lisp/net/net-utils.el
@@ -79,7 +79,7 @@
;; On GNU/Linux and Irix, the system's ping program seems to send packets
;; indefinitely unless told otherwise
(defcustom ping-program-options
- (and (memq system-type '(gnu/linux irix))
+ (and (eq system-type 'gnu/linux)
(list "-c" "4"))
"Options for the ping program.
These options can be used to limit how many ICMP packets are emitted."
@@ -112,22 +112,31 @@ These options can be used to limit how many ICMP packets are emitted."
:group 'net-utils
:type '(repeat string))
-(defcustom iwconfig-program "iwconfig"
+(defcustom iwconfig-program
+ (cond ((executable-find "iwconfig") "iwconfig")
+ ((net-utils--executable-find-sbin "iw") "iw")
+ (t "iw"))
"Program to print wireless network configuration information."
:group 'net-utils
:type 'string
- :version "23.1")
+ :version "26.1")
-(defcustom iwconfig-program-options nil
+(defcustom iwconfig-program-options
+ (cond ((string-match-p "iw\\'" iwconfig-program) (list "dev"))
+ (t nil))
"Options for the iwconfig program."
:group 'net-utils
:type '(repeat string)
- :version "23.1")
+ :version "26.1")
-(defcustom netstat-program "netstat"
+(defcustom netstat-program
+ (cond ((executable-find "netstat") "netstat")
+ ((net-utils--executable-find-sbin "ss"))
+ (t "ss"))
"Program to print network statistics."
:group 'net-utils
- :type 'string)
+ :type 'string
+ :version "26.1")
(defcustom netstat-program-options
(list "-a")
@@ -147,20 +156,25 @@ These options can be used to limit how many ICMP packets are emitted."
:type '(repeat string))
(defcustom route-program
- (if (eq system-type 'windows-nt)
- "route"
- "netstat")
+ (cond ((eq system-type 'windows-nt) "route")
+ ((executable-find "netstat") "netstat")
+ ((net-utils--executable-find-sbin "netstat"))
+ ((executable-find "ip") "ip")
+ ((net-utils--executable-find-sbin "ip"))
+ (t "ip"))
"Program to print routing tables."
:group 'net-utils
- :type 'string)
+ :type 'string
+ :version "26.1")
(defcustom route-program-options
- (if (eq system-type 'windows-nt)
- (list "print")
- (list "-r"))
+ (cond ((eq system-type 'windows-nt) (list "print"))
+ ((string-match-p "netstat\\'" route-program) (list "-r"))
+ (t (list "route")))
"Options for the route program."
:group 'net-utils
- :type '(repeat string))
+ :type '(repeat string)
+ :version "26.1")
(defcustom nslookup-program "nslookup"
"Program to interactively query DNS information."
diff --git a/lisp/net/network-stream.el b/lisp/net/network-stream.el
index 11885987ba5..657672d5e76 100644
--- a/lisp/net/network-stream.el
+++ b/lisp/net/network-stream.el
@@ -1,4 +1,4 @@
-;;; network-stream.el --- open network processes, possibly with encryption
+;;; network-stream.el --- open network processes, possibly with encryption -*- lexical-binding: t -*-
;; Copyright (C) 2010-2016 Free Software Foundation, Inc.
@@ -46,6 +46,7 @@
(require 'starttls)
(require 'auth-source)
(require 'nsm)
+(require 'puny)
(autoload 'gnutls-negotiate "gnutls")
(autoload 'open-gnutls-stream "gnutls")
@@ -64,8 +65,8 @@ BUFFER is a buffer or buffer name to associate with the process.
Process output goes at end of that buffer. BUFFER may be nil,
meaning that the process is not associated with any buffer.
HOST is the name or IP address of the host to connect to.
-SERVICE is the name of the service desired, or an integer specifying
- a port number to connect to.
+SERVICE is the name of the service desired, or an integer or
+ integer string specifying a port number to connect to.
The remaining PARAMETERS should be a sequence of keywords and
values:
@@ -135,8 +136,14 @@ non-nil, is used warn the user if the connection isn't encrypted.
:nogreeting is a boolean that can be used to inhibit waiting for
a greeting from the server.
-:nowait is a boolean that says the connection should be made
-asynchronously, if possible."
+:nowait, if non-nil, says the connection should be made
+asynchronously, if possible.
+
+:tls-parameters is a list that should be supplied if you're
+opening a TLS connection. The first element is the TLS
+type (either `gnutls-x509pki' or `gnutls-anon'), and the
+remaining elements should be a keyword list accepted by
+gnutls-boot (as returned by `gnutls-boot-parameters')."
(unless (featurep 'make-network-process)
(error "Emacs was compiled without networking support"))
(let ((type (plist-get parameters :type))
@@ -148,8 +155,10 @@ asynchronously, if possible."
(plist-get parameters :capability-command))))))
;; The simplest case: wrapper around `make-network-process'.
(make-network-process :name name :buffer buffer
- :host host :service service
- :nowait (plist-get parameters :nowait))
+ :host (puny-encode-domain host) :service service
+ :nowait (plist-get parameters :nowait)
+ :tls-parameters
+ (plist-get parameters :tls-parameters))
(let ((work-buffer (or buffer
(generate-new-buffer " *stream buffer*")))
(fun (cond ((and (eq type 'plain)
@@ -194,11 +203,14 @@ asynchronously, if possible."
;;;###autoload
(defalias 'open-protocol-stream 'open-network-stream)
+(define-obsolete-function-alias 'open-protocol-stream 'open-network-stream
+ "26.1")
(defun network-stream-open-plain (name buffer host service parameters)
(let ((start (with-current-buffer buffer (point)))
(stream (make-network-process :name name :buffer buffer
- :host host :service service
+ :host (puny-encode-domain host)
+ :service service
:nowait (plist-get parameters :nowait))))
(when (plist-get parameters :warn-unless-encrypted)
(setq stream (nsm-verify-connection stream host service nil t)))
@@ -219,7 +231,8 @@ asynchronously, if possible."
eoc))
;; Return (STREAM GREETING CAPABILITIES RESULTING-TYPE)
(stream (make-network-process :name name :buffer buffer
- :host host :service service))
+ :host (puny-encode-domain host)
+ :service service))
(greeting (and (not (plist-get parameters :nogreeting))
(network-stream-get-response stream start eoc)))
(capabilities (network-stream-command stream capability-command
@@ -296,8 +309,12 @@ asynchronously, if possible."
(unless require-tls
(setq stream
(make-network-process :name name :buffer buffer
- :host host :service service))
+ :host (puny-encode-domain host)
+ :service service))
(network-stream-get-response stream start eoc)))
+ (unless (process-live-p stream)
+ (error "Unable to negotiate a TLS connection with %s/%s"
+ host service))
;; Re-get the capabilities, which may have now changed.
(setq capabilities
(network-stream-command stream capability-command eo-capa))))
@@ -355,32 +372,34 @@ asynchronously, if possible."
(with-current-buffer buffer
(let* ((start (point-max))
(stream
- (funcall (if (gnutls-available-p)
- 'open-gnutls-stream
- 'open-tls-stream)
- name buffer host service))
+ (if (gnutls-available-p)
+ (open-gnutls-stream name buffer host service
+ (plist-get parameters :nowait))
+ (open-tls-stream name buffer host service)))
(eoc (plist-get parameters :end-of-command)))
- ;; Check certificate validity etc.
- (when (and (gnutls-available-p) stream)
- (setq stream (nsm-verify-connection stream host service)))
- (if (null stream)
- (list nil nil nil 'plain)
- ;; If we're using tls.el, we have to delete the output from
- ;; openssl/gnutls-cli.
- (when (and (not (gnutls-available-p))
- eoc)
- (network-stream-get-response stream start eoc)
- (goto-char (point-min))
- (when (re-search-forward eoc nil t)
- (goto-char (match-beginning 0))
- (delete-region (point-min) (line-beginning-position))))
- (let ((capability-command (plist-get parameters :capability-command))
- (eo-capa (or (plist-get parameters :end-of-capability)
- eoc)))
- (list stream
- (network-stream-get-response stream start eoc)
- (network-stream-command stream capability-command eo-capa)
- 'tls))))))
+ (if (plist-get parameters :nowait)
+ (list stream nil nil 'tls)
+ ;; Check certificate validity etc.
+ (when (and (gnutls-available-p) stream)
+ (setq stream (nsm-verify-connection stream host service)))
+ (if (null stream)
+ (list nil nil nil 'plain)
+ ;; If we're using tls.el, we have to delete the output from
+ ;; openssl/gnutls-cli.
+ (when (and (not (gnutls-available-p))
+ eoc)
+ (network-stream-get-response stream start eoc)
+ (goto-char (point-min))
+ (when (re-search-forward eoc nil t)
+ (goto-char (match-beginning 0))
+ (delete-region (point-min) (line-beginning-position))))
+ (let ((capability-command (plist-get parameters :capability-command))
+ (eo-capa (or (plist-get parameters :end-of-capability)
+ eoc)))
+ (list stream
+ (network-stream-get-response stream start eoc)
+ (network-stream-command stream capability-command eo-capa)
+ 'tls)))))))
(defun network-stream-open-shell (name buffer host service parameters)
(require 'format-spec)
diff --git a/lisp/net/newst-backend.el b/lisp/net/newst-backend.el
index 2596e56aa47..41b21722723 100644
--- a/lisp/net/newst-backend.el
+++ b/lisp/net/newst-backend.el
@@ -442,13 +442,6 @@ buffers *newsticker-wget-<feed>* will not be closed."
;; FIXME It is bad practice to define compat functions with such generic names.
-;; This is not needed in Emacs >= 22.1.
-(unless (fboundp 'time-add)
- (require 'time-date);;FIXME
- (defun time-add (t1 t2)
- (with-no-warnings ; don't warn about obsolete time-to-seconds in 23.2
- (seconds-to-time (+ (time-to-seconds t1) (time-to-seconds t2))))))
-
(unless (fboundp 'match-string-no-properties)
(defalias 'match-string-no-properties 'match-string))
diff --git a/lisp/net/newsticker.el b/lisp/net/newsticker.el
index 66b7a69aae8..7eff422e4ea 100644
--- a/lisp/net/newsticker.el
+++ b/lisp/net/newsticker.el
@@ -1,4 +1,4 @@
-;;; newsticker.el --- A Newsticker for Emacs.
+;;; newsticker.el --- A Newsticker for Emacs. -*- lexical-binding: t -*-
;; Copyright (C) 2003-2016 Free Software Foundation, Inc.
diff --git a/lisp/net/nsm.el b/lisp/net/nsm.el
index d0b55437732..5928ab303be 100644
--- a/lisp/net/nsm.el
+++ b/lisp/net/nsm.el
@@ -25,6 +25,7 @@
;;; Code:
(require 'cl-lib)
+(require 'subr-x)
(defvar nsm-permanent-host-settings nil)
(defvar nsm-temporary-host-settings nil)
@@ -297,19 +298,30 @@ unencrypted."
nil
(let ((response
(condition-case nil
- (nsm-query-user message args (nsm-format-certificate status))
+ (intern
+ (car (split-string
+ (nsm-query-user message args
+ (nsm-format-certificate status))))
+ obarray)
;; Make sure we manage to close the process if the user hits
;; `C-g'.
(quit 'no)
(error 'no))))
(if (eq response 'no)
- nil
+ (progn
+ (message "Aborting connection to %s:%s" host port)
+ nil)
+ (message (if (eq response 'session)
+ "Accepting certificate for %s:%s this session only"
+ "Permanently accepting certificate for %s:%s")
+ host port)
(nsm-save-host host port status what response)
t))))
(defun nsm-query-user (message args cert)
(let ((buffer (get-buffer-create "*Network Security Manager*")))
(save-window-excursion
+ ;; First format the certificate and warnings.
(with-help-window buffer
(with-current-buffer buffer
(erase-buffer)
@@ -321,28 +333,15 @@ unencrypted."
;; Fill the first line of the message, which usually
;; contains lots of explanatory text.
(fill-region (point) (line-end-position)))))
- (let ((responses '((?n . no)
- (?s . session)
- (?a . always)))
- (prefix "")
- (cursor-in-echo-area t)
- response)
- (while (not response)
- (setq response
- (cdr
- (assq (downcase
- (read-char
- (concat prefix
- "Continue connecting? (No, Session only, Always) ")))
- responses)))
- (unless response
- (ding)
- (setq prefix "Invalid choice. ")))
- (kill-buffer buffer)
- ;; If called from a callback, `read-char' will insert things
- ;; into the pending input. Clear that.
- (clear-this-command-keys)
- response))))
+ ;; Then ask the user what to do about it.
+ (unwind-protect
+ (cadr
+ (read-multiple-choice
+ "Continue connecting?"
+ '((?a "always" "Accept this certificate this session and for all future sessions.")
+ (?s "session only" "Accept this certificate this session only.")
+ (?n "no" "Refuse to use this certificate, and close the connection."))))
+ (kill-buffer buffer)))))
(defun nsm-save-host (host port status what permanency)
(let* ((id (nsm-id host port))
diff --git a/lisp/net/ntlm.el b/lisp/net/ntlm.el
index d96f3b1ebea..e272002cfe7 100644
--- a/lisp/net/ntlm.el
+++ b/lisp/net/ntlm.el
@@ -5,7 +5,7 @@
;; Author: Taro Kawagishi <tarok@transpulse.org>
;; Maintainer: Thomas Fitzsimmons <fitzsim@fitzsim.org>
;; Keywords: NTLM, SASL, comm
-;; Version: 2.0.0
+;; Version: 2.1.0
;; Created: February 2001
;; This file is part of GNU Emacs.
@@ -49,10 +49,12 @@
;;
;; 1. Open a network connection to the Exchange server at the IMAP port (143)
;; 2. Receive an opening message such as:
-;; "* OK Microsoft Exchange IMAP4rev1 server version 5.5.2653.7 (XXXX) ready"
+;; "* OK Microsoft Exchange IMAP4rev1 server
+;; version 5.5.2653.7 (XXXX) ready"
;; 3. Ask for IMAP server capability by sending "NNN capability"
;; 4. Receive a capability message such as:
-;; "* CAPABILITY IMAP4 IMAP4rev1 IDLE LITERAL+ LOGIN-REFERRALS MAILBOX-REFERRALS NAMESPACE AUTH=NTLM"
+;; "* CAPABILITY IMAP4 IMAP4rev1 IDLE LITERAL+
+;; LOGIN-REFERRALS MAILBOX-REFERRALS NAMESPACE AUTH=NTLM"
;; 5. Ask for NTLM authentication by sending a string
;; "NNN authenticate ntlm"
;; 6. Receive continuation acknowledgment "+"
@@ -101,31 +103,34 @@ is not given."
(let ((request-ident (concat "NTLMSSP" (make-string 1 0)))
(request-msgType (concat (make-string 1 1) (make-string 3 0)))
;0x01 0x00 0x00 0x00
- (request-flags (concat (make-string 1 7) (make-string 1 178)
+ (request-flags (concat (make-string 1 7) (make-string 1 130)
(make-string 1 8) (make-string 1 0)))
- ;0x07 0xb2 0x08 0x00
+ ;0x07 0x82 0x08 0x00
lu ld off-d off-u)
- (when (string-match "@" user)
+ (when (and user (string-match "@" user))
(unless domain
(setq domain (substring user (1+ (match-beginning 0)))))
(setq user (substring user 0 (match-beginning 0))))
+ (when (and (stringp domain) (> (length domain) 0))
+ ;; set "negotiate domain supplied" bit
+ (aset request-flags 1 (logior (aref request-flags 1) ?\x10)))
;; set fields offsets within the request struct
(setq lu (length user))
(setq ld (length domain))
(setq off-u 32) ;offset to the string 'user
(setq off-d (+ 32 lu)) ;offset to the string 'domain
;; pack the request struct in a string
- (concat request-ident ;8 bytes
- request-msgType ;4 bytes
- request-flags ;4 bytes
- (md4-pack-int16 lu) ;user field, count field
- (md4-pack-int16 lu) ;user field, max count field
- (md4-pack-int32 (cons 0 off-u)) ;user field, offset field
- (md4-pack-int16 ld) ;domain field, count field
- (md4-pack-int16 ld) ;domain field, max count field
- (md4-pack-int32 (cons 0 off-d)) ;domain field, offset field
- user ;buffer field
- domain ;buffer field
+ (concat request-ident ;8 bytes
+ request-msgType ;4 bytes
+ request-flags ;4 bytes
+ (md4-pack-int16 lu) ;user field, count field
+ (md4-pack-int16 lu) ;user field, max count field
+ (md4-pack-int32 (cons 0 off-u)) ;user field, offset field
+ (md4-pack-int16 ld) ;domain field, count field
+ (md4-pack-int16 ld) ;domain field, max count field
+ (md4-pack-int32 (cons 0 off-d)) ;domain field, offset field
+ user ;buffer field
+ domain ;buffer field
)))
(eval-when-compile
@@ -178,6 +183,10 @@ by PASSWORD-HASHES. PASSWORD-HASHES should be a return value of
;;(ident (substring rchallenge 0 8)) ;ident, 8 bytes
;;(msgType (substring rchallenge 8 12)) ;msgType, 4 bytes
(uDomain (substring rchallenge 12 20)) ;uDomain, 8 bytes
+ ;; match default setting in `ntlm-build-auth-request'
+ (request-flags (concat (make-string 1 7) (make-string 1 130)
+ (make-string 1 8) (make-string 1 0)))
+ ;0x07 0x82 0x08 0x00
(flags (substring rchallenge 20 24)) ;flags, 4 bytes
(challengeData (substring rchallenge 24 32)) ;challengeData, 8 bytes
uDomain-len uDomain-offs
@@ -185,19 +194,28 @@ by PASSWORD-HASHES. PASSWORD-HASHES should be a return value of
lmRespData ;lmRespData, 24 bytes
ntRespData ;ntRespData, variable length
domain ;ascii domain string
- lu ld ln off-lm off-nt off-d off-u off-w off-s)
+ workstation ;ascii workstation string
+ ll ln lu ld lw off-lm off-nt off-u off-d off-w)
;; extract domain string from challenge string
(setq uDomain-len (md4-unpack-int16 (substring uDomain 0 2)))
(setq uDomain-offs (md4-unpack-int32 (substring uDomain 4 8)))
- (setq domain
- (ntlm-unicode2ascii (substring challenge
- (cdr uDomain-offs)
- (+ (cdr uDomain-offs) uDomain-len))
- (/ uDomain-len 2)))
+ ;; match Mozilla behavior, which is to send an empty domain string
+ (setq domain "")
+ ;; match Mozilla behavior, which is to send "WORKSTATION"
+ (setq workstation "WORKSTATION")
;; overwrite domain in case user is given in <user>@<domain> format
(when (string-match "@" user)
(setq domain (substring user (1+ (match-beginning 0))))
(setq user (substring user 0 (match-beginning 0))))
+ (when (and (stringp domain) (> (length domain) 0))
+ ;; set "negotiate domain supplied" bit, since presumably domain
+ ;; was also set in `ntlm-build-auth-request'
+ (aset request-flags 1 (logior (aref request-flags 1) ?\x10)))
+ ;; match Mozilla behavior, which is to send the logical and of the
+ ;; type 1 and type 2 flags
+ (dotimes (index 4)
+ (aset flags index (logand (aref flags index)
+ (aref request-flags index))))
(unless (and (integerp ntlm-compatibility-level)
(>= ntlm-compatibility-level 0)
@@ -223,22 +241,20 @@ by PASSWORD-HASHES. PASSWORD-HASHES should be a return value of
(cadr password-hashes)))
(nonce (ntlm-generate-nonce))
(blob (concat (make-string 2 1)
- (make-string 2 0) ; blob signature
- (make-string 4 0) ; reserved value
- (ntlm-compute-timestamp) ; timestamp
- nonce ; client nonce
- (make-string 4 0) ; unknown
- targetInfo ; target info
- (make-string 4 0))) ; unknown
+ (make-string 2 0) ;blob signature
+ (make-string 4 0) ;reserved value
+ (ntlm-compute-timestamp) ;timestamp
+ nonce ;client nonce
+ (make-string 4 0) ;unknown
+ targetInfo)) ;target info
;; for reference: LMv2 interim calculation
- ;; (lm-interim (hmac-md5 (concat challengeData nonce)
- ;; ntlmv2-hash))
+ (lm-interim (hmac-md5 (concat challengeData nonce)
+ ntlmv2-hash))
(nt-interim (hmac-md5 (concat challengeData blob)
ntlmv2-hash)))
;; for reference: LMv2 field, but match other clients that
;; send all zeros
- ;; (setq lmRespData (concat lm-interim nonce))
- (setq lmRespData (make-string 24 0))
+ (setq lmRespData (concat lm-interim nonce))
(setq ntRespData (concat nt-interim blob))))
;; compatibility level is 2, 1 or 0
;; level 2 should be treated specially but it's not clear how,
@@ -263,69 +279,69 @@ by PASSWORD-HASHES. PASSWORD-HASHES should be a return value of
(ntlm-smb-owf-encrypt (cadr password-hashes) challengeData))))
;; get offsets to fields to pack the response struct in a string
+ (setq ll (length lmRespData))
+ (setq ln (length ntRespData))
(setq lu (length user))
(setq ld (length domain))
- (setq ln (length ntRespData))
- (setq off-lm 64) ;offset to string 'lmResponse
- (setq off-nt (+ 64 24)) ;offset to string 'ntResponse
- (setq off-d (+ 64 24 ln)) ;offset to string 'uDomain
- (setq off-u (+ 64 24 ln (* 2 ld))) ;offset to string 'uUser
- (setq off-w (+ 64 24 ln (* 2 (+ ld lu)))) ;offset to string 'uWks
- (setq off-s (+ 64 24 ln (* 2 (+ ld lu lu)))) ;offset to string 'sessionKey
+ (setq lw (length workstation))
+ (setq off-u 64) ;offset to string 'uUser
+ (setq off-d (+ off-u (* 2 lu))) ;offset to string 'uDomain
+ (setq off-w (+ off-d (* 2 ld))) ;offset to string 'uWks
+ (setq off-lm (+ off-w (* 2 lw))) ;offset to string 'lmResponse
+ (setq off-nt (+ off-lm ll)) ;offset to string 'ntResponse
;; pack the response struct in a string
- (concat "NTLMSSP\0" ;response ident field, 8 bytes
- (md4-pack-int32 '(0 . 3)) ;response msgType field, 4 bytes
+ (concat "NTLMSSP\0" ;response ident field, 8 bytes
+ (md4-pack-int32 '(0 . 3)) ;response msgType field, 4 bytes
;; lmResponse field, 8 bytes
;;AddBytes(response,lmResponse,lmRespData,24);
- (md4-pack-int16 24) ;len field
- (md4-pack-int16 24) ;maxlen field
- (md4-pack-int32 (cons 0 off-lm)) ;field offset
+ (md4-pack-int16 ll) ;len field
+ (md4-pack-int16 ll) ;maxlen field
+ (md4-pack-int32 (cons 0 off-lm)) ;field offset
;; ntResponse field, 8 bytes
;;AddBytes(response,ntResponse,ntRespData,ln);
- (md4-pack-int16 ln) ;len field
- (md4-pack-int16 ln) ;maxlen field
- (md4-pack-int32 (cons 0 off-nt)) ;field offset
+ (md4-pack-int16 ln) ;len field
+ (md4-pack-int16 ln) ;maxlen field
+ (md4-pack-int32 (cons 0 off-nt)) ;field offset
;; uDomain field, 8 bytes
;;AddUnicodeString(response,uDomain,domain);
;;AddBytes(response, uDomain, udomain, 2*ld);
- (md4-pack-int16 (* 2 ld)) ;len field
- (md4-pack-int16 (* 2 ld)) ;maxlen field
- (md4-pack-int32 (cons 0 off-d)) ;field offset
+ (md4-pack-int16 (* 2 ld)) ;len field
+ (md4-pack-int16 (* 2 ld)) ;maxlen field
+ ;; match Mozilla behavior, which is to hard-code the
+ ;; domain offset to 64
+ (md4-pack-int32 (cons 0 64)) ;field offset
;; uUser field, 8 bytes
;;AddUnicodeString(response,uUser,u);
;;AddBytes(response, uUser, uuser, 2*lu);
- (md4-pack-int16 (* 2 lu)) ;len field
- (md4-pack-int16 (* 2 lu)) ;maxlen field
- (md4-pack-int32 (cons 0 off-u)) ;field offset
+ (md4-pack-int16 (* 2 lu)) ;len field
+ (md4-pack-int16 (* 2 lu)) ;maxlen field
+ (md4-pack-int32 (cons 0 off-u)) ;field offset
;; uWks field, 8 bytes
;;AddUnicodeString(response,uWks,u);
- (md4-pack-int16 (* 2 lu)) ;len field
- (md4-pack-int16 (* 2 lu)) ;maxlen field
- (md4-pack-int32 (cons 0 off-w)) ;field offset
+ (md4-pack-int16 (* 2 lw)) ;len field
+ (md4-pack-int16 (* 2 lw)) ;maxlen field
+ (md4-pack-int32 (cons 0 off-w)) ;field offset
- ;; sessionKey field, 8 bytes
+ ;; sessionKey field, blank, 8 bytes
;;AddString(response,sessionKey,NULL);
- (md4-pack-int16 0) ;len field
- (md4-pack-int16 0) ;maxlen field
- (md4-pack-int32 (cons 0 (- off-s off-lm))) ;field offset
+ (md4-pack-int16 0) ;len field
+ (md4-pack-int16 0) ;maxlen field
+ (md4-pack-int32 (cons 0 0)) ;field offset
;; flags field, 4 bytes
- flags ;
+ flags
;; buffer field
- lmRespData ;lmResponse, 24 bytes
- ntRespData ;ntResponse, 24 bytes
- (ntlm-ascii2unicode domain ;Unicode domain string, 2*ld bytes
- (length domain)) ;
- (ntlm-ascii2unicode user ;Unicode user string, 2*lu bytes
- (length user)) ;
- (ntlm-ascii2unicode user ;Unicode user string, 2*lu bytes
- (length user)) ;
+ (ntlm-ascii2unicode user lu) ;Unicode user, 2*lu bytes
+ (ntlm-ascii2unicode domain ld) ;Unicode domain, 2*ld bytes
+ (ntlm-ascii2unicode workstation lw) ;Unicode workstation, 2*lw bytes
+ lmRespData ;lmResponse, 24 bytes
+ ntRespData ;ntResponse, ln bytes
)))
(defun ntlm-get-password-hashes (password)
@@ -544,7 +560,7 @@ length of STR is LEN."
(concat (substring str c len) (substring str 0 c))))
(defsubst ntlm-string-xor (in1 in2 n)
- "Return exclusive-or of sequences in1 and in2"
+ "Return exclusive-or of sequences in1 and in2."
(let ((w (make-string n 0)) (i 0))
(while (< i n)
(aset w i (logxor (aref in1 i) (aref in2 i)))
diff --git a/lisp/net/pop3.el b/lisp/net/pop3.el
new file mode 100644
index 00000000000..3964288fd23
--- /dev/null
+++ b/lisp/net/pop3.el
@@ -0,0 +1,915 @@
+;;; pop3.el --- Post Office Protocol (RFC 1460) interface
+
+;; Copyright (C) 1996-2016 Free Software Foundation, Inc.
+
+;; Author: Richard L. Pieri <ratinox@peorth.gweep.net>
+;; Maintainer: emacs-devel@gnu.org
+;; Keywords: mail
+
+;; 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 3 of the License, 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. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Most of the standard Post Office Protocol version 3 (RFC 1460) commands
+;; are implemented. The LIST command has not been implemented due to lack
+;; of actual usefulness.
+;; The optional POP3 command TOP has not been implemented.
+
+;; This program was inspired by Kyle E. Jones's vm-pop program.
+
+;;; Code:
+
+(eval-when-compile (require 'cl))
+
+(require 'mail-utils)
+(defvar parse-time-months)
+
+(defgroup pop3 nil
+ "Post Office Protocol."
+ :group 'mail
+ :group 'mail-source)
+
+(defcustom pop3-maildrop (or (user-login-name)
+ (getenv "LOGNAME")
+ (getenv "USER"))
+ "POP3 maildrop."
+ :version "22.1" ;; Oort Gnus
+ :type 'string
+ :group 'pop3)
+
+(defcustom pop3-mailhost (or (getenv "MAILHOST") ;; nil -> mismatch
+ "pop3")
+ "POP3 mailhost."
+ :version "22.1" ;; Oort Gnus
+ :type 'string
+ :group 'pop3)
+
+(defcustom pop3-port 110
+ "POP3 port."
+ :version "22.1" ;; Oort Gnus
+ :type 'number
+ :group 'pop3)
+
+(defcustom pop3-password-required t
+ "Non-nil if a password is required when connecting to POP server."
+ :version "22.1" ;; Oort Gnus
+ :type 'boolean
+ :group 'pop3)
+
+;; Should this be customizable?
+(defcustom pop3-password nil
+ "Password to use when connecting to POP server."
+ :type '(choice (const nil) string)
+ :group 'pop3)
+
+(defcustom pop3-authentication-scheme 'pass
+ "POP3 authentication scheme.
+Defaults to `pass', for the standard USER/PASS authentication. The other
+valid value is `apop'."
+ :type '(choice (const :tag "Normal user/password" pass)
+ (const :tag "APOP" apop))
+ :version "22.1" ;; Oort Gnus
+ :group 'pop3)
+
+(defcustom pop3-stream-length 100
+ "How many messages should be requested at one time.
+The lower the number, the more latency-sensitive the fetching
+will be. If your pop3 server doesn't support streaming at all,
+set this to 1."
+ :type 'number
+ :version "24.1"
+ :group 'pop3)
+
+(defcustom pop3-leave-mail-on-server nil
+ "Non-nil if the mail is to be left on the POP server after fetching.
+Mails once fetched will never be fetched again by the UIDL control.
+
+If this is neither nil nor a number, all mails will be left on the
+server. If this is a number, leave mails on the server for this many
+days since you first checked new mails. If this is nil, mails will be
+deleted on the server right after fetching.
+
+Gnus users should use the `:leave' keyword in a mail source to direct
+the behavior per server, rather than directly modifying this value.
+
+Note that POP servers maintain no state information between sessions,
+so what the client believes is there and what is actually there may
+not match up. If they do not, then you may get duplicate mails or
+the whole thing can fall apart and leave you with a corrupt mailbox."
+ :version "24.4"
+ :type '(choice (const :tag "Don't leave mails" nil)
+ (const :tag "Leave all mails" t)
+ (number :tag "Leave mails for this many days" :value 14))
+ :group 'pop3)
+
+(defcustom pop3-uidl-file "~/.pop3-uidl"
+ "File used to save UIDL."
+ :version "24.4"
+ :type 'file
+ :group 'pop3)
+
+(defcustom pop3-uidl-file-backup '(0 9)
+ "How to backup the UIDL file `pop3-uidl-file' when updating.
+If it is a list of numbers, the first one binds `kept-old-versions' and
+the other binds `kept-new-versions' to keep number of oldest and newest
+versions. Otherwise, the value binds `version-control' (which see).
+
+Note: Backup will take place whenever you check new mails on a server.
+So, you may lose the backup files having been saved before a trouble
+if you set it so as to make too few backups whereas you have access to
+many servers."
+ :version "24.4"
+ :type '(choice (group :tag "Keep versions" :format "\n%v" :indent 3
+ (number :tag "oldest")
+ (number :tag "newest"))
+ (sexp :format "%v"
+ :match (lambda (widget value)
+ (condition-case nil
+ (not (and (numberp (car value))
+ (numberp (car (cdr value)))))
+ (error t)))))
+ :group 'pop3)
+
+(defvar pop3-timestamp nil
+ "Timestamp returned when initially connected to the POP server.
+Used for APOP authentication.")
+
+(defvar pop3-read-point nil)
+(defvar pop3-debug nil)
+
+;; Borrowed from nnheader-accept-process-output in nnheader.el. See the
+;; comments there for explanations about the values.
+
+(eval-and-compile
+ (if (and (fboundp 'nnheader-accept-process-output)
+ (boundp 'nnheader-read-timeout))
+ (defalias 'pop3-accept-process-output 'nnheader-accept-process-output)
+ ;; Borrowed from `nnheader.el':
+ (defvar pop3-read-timeout
+ (if (string-match "windows-nt\\|os/2\\|cygwin"
+ (symbol-name system-type))
+ 1.0
+ 0.01)
+ "How long pop3 should wait between checking for the end of output.
+Shorter values mean quicker response, but are more CPU intensive.")
+ (defun pop3-accept-process-output (process)
+ (accept-process-output
+ process
+ (truncate pop3-read-timeout)
+ (truncate (* (- pop3-read-timeout
+ (truncate pop3-read-timeout))
+ 1000))))))
+
+(defvar pop3-uidl)
+;; List of UIDLs of existing messages at present in the server:
+;; ("UIDL1" "UIDL2" "UIDL3"...)
+
+(defvar pop3-uidl-saved)
+;; Locally saved UIDL data; an alist of the server, the user, and the UIDL
+;; and timestamp pairs:
+;; (("SERVER_A" ("USER_A1" "UIDL1" TIMESTAMP1 "UIDL2" TIMESTAMP2...)
+;; ("USER_A2" "UIDL1" TIMESTAMP1 "UIDL2" TIMESTAMP2...)
+;; ...)
+;; ("SERVER_B" ("USER_B1" "UIDL1" TIMESTAMP1 "UIDL2" TIMESTAMP2...)
+;; ("USER_B2" "UIDL1" TIMESTAMP1 "UIDL2" TIMESTAMP2...)
+;; ...))
+;; Where TIMESTAMP is the most significant two digits of an Emacs time,
+;; i.e. the return value of `current-time'.
+
+;;;###autoload
+(defun pop3-movemail (file)
+ "Transfer contents of a maildrop to the specified FILE.
+Use streaming commands."
+ (let ((process (pop3-open-server pop3-mailhost pop3-port))
+ messages total-size
+ pop3-uidl
+ pop3-uidl-saved)
+ (pop3-logon process)
+ (if pop3-leave-mail-on-server
+ (setq messages (pop3-uidl-stat process)
+ total-size (cadr messages)
+ messages (car messages))
+ (let ((size (pop3-stat process)))
+ (dotimes (i (car size)) (push (1+ i) messages))
+ (setq messages (nreverse messages)
+ total-size (cadr size))))
+ (when messages
+ (with-current-buffer (process-buffer process)
+ (pop3-send-streaming-command process "RETR" messages total-size)
+ (pop3-write-to-file file messages)
+ (unless pop3-leave-mail-on-server
+ (pop3-send-streaming-command process "DELE" messages nil))))
+ (if pop3-leave-mail-on-server
+ (when (prog1 (pop3-uidl-dele process) (pop3-quit process))
+ (pop3-uidl-save))
+ (pop3-quit process)
+ ;; Remove UIDL data for the account that got not to leave mails.
+ (setq pop3-uidl-saved (pop3-uidl-load))
+ (let ((elt (assoc pop3-maildrop
+ (cdr (assoc pop3-mailhost pop3-uidl-saved)))))
+ (when elt
+ (setcdr elt nil)
+ (pop3-uidl-save))))
+ t))
+
+(defun pop3-send-streaming-command (process command messages total-size)
+ (erase-buffer)
+ (let ((count (length messages))
+ (i 1)
+ (start-point (point-min))
+ (waited-for 0))
+ (while messages
+ (process-send-string process (format "%s %d\r\n" command (pop messages)))
+ ;; Only do 100 messages at a time to avoid pipe stalls.
+ (when (zerop (% i pop3-stream-length))
+ (setq start-point
+ (pop3-wait-for-messages process pop3-stream-length
+ total-size start-point))
+ (incf waited-for pop3-stream-length))
+ (incf i))
+ (pop3-wait-for-messages process (- count waited-for)
+ total-size start-point)))
+
+(defun pop3-wait-for-messages (process count total-size start-point)
+ (while (> count 0)
+ (goto-char start-point)
+ (while (or (and (re-search-forward "^\\+OK" nil t)
+ (or (not total-size)
+ (re-search-forward "^\\.\r?\n" nil t)))
+ (re-search-forward "^-ERR " nil t))
+ (decf count)
+ (setq start-point (point)))
+ (unless (memq (process-status process) '(open run))
+ (error "pop3 process died"))
+ (when total-size
+ (let ((size 0))
+ (goto-char (point-min))
+ (while (re-search-forward "^\\+OK.*\n" nil t)
+ (setq size (+ size (- (point))
+ (if (re-search-forward "^\\.\r?\n" nil 'move)
+ (match-beginning 0)
+ (point)))))
+ (message "pop3 retrieved %dKB (%d%%)"
+ (truncate (/ size 1000))
+ (truncate (* (/ (* size 1.0) total-size) 100)))))
+ (pop3-accept-process-output process))
+ start-point)
+
+(defun pop3-write-to-file (file messages)
+ (let ((pop-buffer (current-buffer))
+ (start (point-min))
+ beg end
+ temp-buffer)
+ (with-temp-buffer
+ (setq temp-buffer (current-buffer))
+ (with-current-buffer pop-buffer
+ (goto-char (point-min))
+ (while (re-search-forward "^\\+OK" nil t)
+ (forward-line 1)
+ (setq beg (point))
+ (when (re-search-forward "^\\.\r?\n" nil t)
+ (setq start (point))
+ (forward-line -1)
+ (setq end (point)))
+ (with-current-buffer temp-buffer
+ (goto-char (point-max))
+ (let ((hstart (point)))
+ (insert-buffer-substring pop-buffer beg end)
+ (pop3-clean-region hstart (point))
+ (goto-char (point-max))
+ (pop3-munge-message-separator hstart (point))
+ (when pop3-leave-mail-on-server
+ (pop3-uidl-add-xheader hstart (pop messages)))
+ (goto-char (point-max))))))
+ (let ((coding-system-for-write 'binary))
+ (goto-char (point-min))
+ ;; Check whether something inserted a newline at the start and
+ ;; delete it.
+ (when (eolp)
+ (delete-char 1))
+ (write-region (point-min) (point-max) file nil 'nomesg)))))
+
+(defun pop3-logon (process)
+ (let ((pop3-password pop3-password))
+ ;; for debugging only
+ (if pop3-debug (switch-to-buffer (process-buffer process)))
+ ;; query for password
+ (if (and pop3-password-required (not pop3-password))
+ (setq pop3-password
+ (read-passwd (format "Password for %s: " pop3-maildrop))))
+ (cond ((equal 'apop pop3-authentication-scheme)
+ (pop3-apop process pop3-maildrop))
+ ((equal 'pass pop3-authentication-scheme)
+ (pop3-user process pop3-maildrop)
+ (pop3-pass process))
+ (t (error "Invalid POP3 authentication scheme")))))
+
+(defun pop3-get-message-count ()
+ "Return the number of messages in the maildrop."
+ (let* ((process (pop3-open-server pop3-mailhost pop3-port))
+ message-count
+ (pop3-password pop3-password))
+ ;; for debugging only
+ (if pop3-debug (switch-to-buffer (process-buffer process)))
+ ;; query for password
+ (if (and pop3-password-required (not pop3-password))
+ (setq pop3-password
+ (read-passwd (format "Password for %s: " pop3-maildrop))))
+ (cond ((equal 'apop pop3-authentication-scheme)
+ (pop3-apop process pop3-maildrop))
+ ((equal 'pass pop3-authentication-scheme)
+ (pop3-user process pop3-maildrop)
+ (pop3-pass process))
+ (t (error "Invalid POP3 authentication scheme")))
+ (setq message-count (car (pop3-stat process)))
+ (pop3-quit process)
+ message-count))
+
+(defun pop3-uidl-stat (process)
+ "Return a list of unread message numbers and total size."
+ (pop3-send-command process "UIDL")
+ (let (err messages size)
+ (if (condition-case code
+ (progn
+ (pop3-read-response process)
+ t)
+ (error (setq err (error-message-string code))
+ nil))
+ (let ((start pop3-read-point)
+ saved list)
+ (with-current-buffer (process-buffer process)
+ (while (not (re-search-forward "^\\.\r\n" nil t))
+ (unless (memq (process-status process) '(open run))
+ (error "pop3 server closed the connection"))
+ (pop3-accept-process-output process)
+ (goto-char start))
+ (setq pop3-read-point (point-marker)
+ pop3-uidl nil)
+ (while (progn (forward-line -1) (>= (point) start))
+ (when (looking-at "[0-9]+ \\([^\n\r ]+\\)")
+ (push (match-string 1) pop3-uidl)))
+ (when pop3-uidl
+ (setq pop3-uidl-saved (pop3-uidl-load)
+ saved (cdr (assoc pop3-maildrop
+ (cdr (assoc pop3-mailhost
+ pop3-uidl-saved)))))
+ (let ((i (length pop3-uidl)))
+ (while (> i 0)
+ (unless (member (nth (1- i) pop3-uidl) saved)
+ (push i messages))
+ (decf i)))
+ (when messages
+ (setq list (pop3-list process)
+ size 0)
+ (dolist (msg messages)
+ (setq size (+ size (cdr (assq msg list)))))
+ (list messages size)))))
+ (message "%s doesn't support UIDL (%s), so we try a regressive way..."
+ pop3-mailhost err)
+ (sit-for 1)
+ (setq size (pop3-stat process))
+ (dotimes (i (car size)) (push (1+ i) messages))
+ (setcar size (nreverse messages))
+ size)))
+
+(defun pop3-uidl-dele (process)
+ "Delete messages according to `pop3-leave-mail-on-server'.
+Return non-nil if it is necessary to update the local UIDL file."
+ (let* ((ctime (current-time))
+ (srvr (assoc pop3-mailhost pop3-uidl-saved))
+ (saved (assoc pop3-maildrop (cdr srvr)))
+ i uidl mod new tstamp dele)
+ (setcdr (cdr ctime) nil)
+ ;; Add new messages to the data to be saved.
+ (cond ((and pop3-uidl saved)
+ (setq i (1- (length pop3-uidl)))
+ (while (>= i 0)
+ (unless (member (setq uidl (nth i pop3-uidl)) (cdr saved))
+ (push ctime new)
+ (push uidl new))
+ (decf i)))
+ (pop3-uidl
+ (setq new (mapcan (lambda (elt) (list elt ctime)) pop3-uidl))))
+ (when new (setq mod t))
+ ;; List expirable messages and delete them from the data to be saved.
+ (setq ctime (when (numberp pop3-leave-mail-on-server)
+ (/ (+ (* (car ctime) 65536.0) (cadr ctime)) 86400))
+ i (1- (length saved)))
+ (while (> i 0)
+ (if (member (setq uidl (nth (1- i) saved)) pop3-uidl)
+ (progn
+ (setq tstamp (nth i saved))
+ (if (and ctime
+ (> (- ctime (/ (+ (* (car tstamp) 65536.0) (cadr tstamp))
+ 86400))
+ pop3-leave-mail-on-server))
+ ;; Mails to delete.
+ (progn
+ (setq mod t)
+ (push uidl dele))
+ ;; Mails to keep.
+ (push tstamp new)
+ (push uidl new)))
+ ;; Mails having been deleted in the server.
+ (setq mod t))
+ (decf i 2))
+ (cond (saved
+ (setcdr saved new))
+ (srvr
+ (setcdr (last srvr) (list (cons pop3-maildrop new))))
+ (t
+ (add-to-list 'pop3-uidl-saved
+ (list pop3-mailhost (cons pop3-maildrop new))
+ t)))
+ ;; Actually delete the messages in the server.
+ (when dele
+ (setq uidl nil
+ i (length pop3-uidl))
+ (while (> i 0)
+ (when (member (nth (1- i) pop3-uidl) dele)
+ (push i uidl))
+ (decf i))
+ (when uidl
+ (pop3-send-streaming-command process "DELE" uidl nil)))
+ mod))
+
+(defun pop3-uidl-load ()
+ "Load saved UIDL."
+ (when (file-exists-p pop3-uidl-file)
+ (with-temp-buffer
+ (condition-case code
+ (progn
+ (insert-file-contents pop3-uidl-file)
+ (goto-char (point-min))
+ (read (current-buffer)))
+ (error
+ (message "Error while loading %s (%s)"
+ pop3-uidl-file (error-message-string code))
+ (sit-for 1)
+ nil)))))
+
+(defun pop3-uidl-save ()
+ "Save UIDL."
+ (with-temp-buffer
+ (if pop3-uidl-saved
+ (progn
+ (insert "(")
+ (dolist (srvr pop3-uidl-saved)
+ (when (cdr srvr)
+ (insert "(\"" (pop srvr) "\"\n ")
+ (dolist (elt srvr)
+ (when (cdr elt)
+ (insert "(\"" (pop elt) "\"\n ")
+ (while elt
+ (insert (format "\"%s\" %s\n " (pop elt) (pop elt))))
+ (delete-char -4)
+ (insert ")\n ")))
+ (delete-char -3)
+ (if (eq (char-before) ?\))
+ (insert ")\n ")
+ (goto-char (1+ (point-at-bol)))
+ (delete-region (point) (point-max)))))
+ (when (eq (char-before) ? )
+ (delete-char -2))
+ (insert ")\n"))
+ (insert "()\n"))
+ (let ((buffer-file-name pop3-uidl-file)
+ (delete-old-versions t)
+ (kept-new-versions kept-new-versions)
+ (kept-old-versions kept-old-versions)
+ (version-control version-control))
+ (if (consp pop3-uidl-file-backup)
+ (setq kept-new-versions (cadr pop3-uidl-file-backup)
+ kept-old-versions (car pop3-uidl-file-backup)
+ version-control t)
+ (setq version-control pop3-uidl-file-backup))
+ (save-buffer))))
+
+(defun pop3-uidl-add-xheader (start msgno)
+ "Add X-UIDL header."
+ (let ((case-fold-search t))
+ (save-restriction
+ (narrow-to-region start (progn
+ (goto-char start)
+ (search-forward "\n\n" nil 'move)
+ (1- (point))))
+ (goto-char start)
+ (while (re-search-forward "^x-uidl:" nil t)
+ (while (progn
+ (forward-line 1)
+ (memq (char-after) '(?\t ? ))))
+ (delete-region (match-beginning 0) (point)))
+ (goto-char (point-max))
+ (insert "X-UIDL: " (nth (1- msgno) pop3-uidl) "\n"))))
+
+(defcustom pop3-stream-type nil
+ "Transport security type for POP3 connections.
+This may be either nil (plain connection), `ssl' (use an
+SSL/TSL-secured stream) or `starttls' (use the starttls mechanism
+to turn on TLS security after opening the stream). However, if
+this is nil, `ssl' is assumed for connections to port
+995 (pop3s)."
+ :version "23.1" ;; No Gnus
+ :group 'pop3
+ :type '(choice (const :tag "Plain" nil)
+ (const :tag "SSL/TLS" ssl)
+ (const starttls)))
+
+(defun pop3-open-server (mailhost port)
+ "Open TCP connection to MAILHOST on PORT.
+Returns the process associated with the connection."
+ (let ((coding-system-for-read 'binary)
+ (coding-system-for-write 'binary)
+ result)
+ (with-current-buffer
+ (get-buffer-create (concat " trace of POP session to "
+ mailhost))
+ (erase-buffer)
+ (setq pop3-read-point (point-min))
+ (setq result
+ (open-network-stream
+ "POP" (current-buffer) mailhost port
+ :type (cond
+ ((or (eq pop3-stream-type 'ssl)
+ (and (not pop3-stream-type)
+ (member port '(995 "pop3s"))))
+ 'tls)
+ (t
+ (or pop3-stream-type 'network)))
+ :warn-unless-encrypted t
+ :capability-command "CAPA\r\n"
+ :end-of-command "^\\(-ERR\\|+OK\\).*\n"
+ :end-of-capability "^\\.\r?\n\\|^-ERR"
+ :success "^\\+OK.*\n"
+ :return-list t
+ :starttls-function
+ (lambda (capabilities)
+ (and (string-match "\\bSTLS\\b" capabilities)
+ "STLS\r\n"))))
+ (when result
+ (let ((response (plist-get (cdr result) :greeting)))
+ (setq pop3-timestamp
+ (substring response (or (string-match "<" response) 0)
+ (+ 1 (or (string-match ">" response) -1)))))
+ (set-process-query-on-exit-flag (car result) nil)
+ (erase-buffer)
+ (car result)))))
+
+;; Support functions
+
+(defun pop3-send-command (process command)
+ (set-buffer (process-buffer process))
+ (goto-char (point-max))
+ ;; (if (= (aref command 0) ?P)
+ ;; (insert "PASS <omitted>\r\n")
+ ;; (insert command "\r\n"))
+ (setq pop3-read-point (point))
+ (goto-char (point-max))
+ (process-send-string process (concat command "\r\n")))
+
+(defun pop3-read-response (process &optional return)
+ "Read the response from the server.
+Return the response string if optional second argument is non-nil."
+ (let ((case-fold-search nil)
+ match-end)
+ (with-current-buffer (process-buffer process)
+ (goto-char pop3-read-point)
+ (while (and (memq (process-status process) '(open run))
+ (not (search-forward "\r\n" nil t)))
+ (pop3-accept-process-output process)
+ (goto-char pop3-read-point))
+ (setq match-end (point))
+ (goto-char pop3-read-point)
+ (if (looking-at "-ERR")
+ (error "%s" (buffer-substring (point) (- match-end 2)))
+ (if (not (looking-at "+OK"))
+ (progn (setq pop3-read-point match-end) nil)
+ (setq pop3-read-point match-end)
+ (if return
+ (buffer-substring (point) match-end)
+ t)
+ )))))
+
+(defun pop3-clean-region (start end)
+ (setq end (set-marker (make-marker) end))
+ (save-excursion
+ (goto-char start)
+ (while (and (< (point) end) (search-forward "\r\n" end t))
+ (replace-match "\n" t t))
+ (goto-char start)
+ (while (and (< (point) end) (re-search-forward "^\\." end t))
+ (replace-match "" t t)
+ (forward-char)))
+ (set-marker end nil))
+
+;; Copied from message-make-date.
+(defun pop3-make-date (&optional now)
+ "Make a valid date header.
+If NOW, use that time instead."
+ (require 'parse-time)
+ (let* ((now (or now (current-time)))
+ (zone (nth 8 (decode-time now)))
+ (sign "+"))
+ (when (< zone 0)
+ (setq sign "-")
+ (setq zone (- zone)))
+ (concat
+ (format-time-string "%d" now)
+ ;; The month name of the %b spec is locale-specific. Pfff.
+ (format " %s "
+ (capitalize (car (rassoc (nth 4 (decode-time now))
+ parse-time-months))))
+ (format-time-string "%Y %H:%M:%S %z" now))))
+
+(defun pop3-munge-message-separator (start end)
+ "Check to see if a message separator exists. If not, generate one."
+ (save-excursion
+ (save-restriction
+ (narrow-to-region start end)
+ (goto-char (point-min))
+ (if (not (or (looking-at "From .?") ; Unix mail
+ (looking-at "\001\001\001\001\n") ; MMDF
+ (looking-at "BABYL OPTIONS:") ; Babyl
+ ))
+ (let* ((from (mail-strip-quoted-names (mail-fetch-field "From")))
+ (tdate (mail-fetch-field "Date"))
+ (date (split-string (or (and tdate
+ (not (string= "" tdate))
+ tdate)
+ (pop3-make-date))
+ " "))
+ (From_))
+ ;; sample date formats I have seen
+ ;; Date: Tue, 9 Jul 1996 09:04:21 -0400 (EDT)
+ ;; Date: 08 Jul 1996 23:22:24 -0400
+ ;; should be
+ ;; Tue Jul 9 09:04:21 1996
+
+ ;; Fixme: This should use timezone on the date field contents.
+ (setq date
+ (cond ((not date)
+ "Tue Jan 1 00:00:0 1900")
+ ((string-match "[A-Z]" (nth 0 date))
+ (format "%s %s %s %s %s"
+ (nth 0 date) (nth 2 date) (nth 1 date)
+ (nth 4 date) (nth 3 date)))
+ (t
+ ;; this really needs to be better but I don't feel
+ ;; like writing a date to day converter.
+ (format "Sun %s %s %s %s"
+ (nth 1 date) (nth 0 date)
+ (nth 3 date) (nth 2 date)))
+ ))
+ (setq From_ (format "\nFrom %s %s\n" from date))
+ (while (string-match "," From_)
+ (setq From_ (concat (substring From_ 0 (match-beginning 0))
+ (substring From_ (match-end 0)))))
+ (goto-char (point-min))
+ (insert From_)
+ (if (search-forward "\n\n" nil t)
+ nil
+ (goto-char (point-max))
+ (insert "\n"))
+ (let ((size (- (point-max) (point))))
+ (forward-line -1)
+ (insert (format "Content-Length: %s\n" size)))
+ )))))
+
+;; The Command Set
+
+;; AUTHORIZATION STATE
+
+(defun pop3-user (process user)
+ "Send USER information to POP3 server."
+ (pop3-send-command process (format "USER %s" user))
+ (let ((response (pop3-read-response process t)))
+ (if (not (and response (string-match "+OK" response)))
+ (error "USER %s not valid" user))))
+
+(defun pop3-pass (process)
+ "Send authentication information to the server."
+ (pop3-send-command process (format "PASS %s" pop3-password))
+ (let ((response (pop3-read-response process t)))
+ (if (not (and response (string-match "+OK" response)))
+ (pop3-quit process))))
+
+(defun pop3-apop (process user)
+ "Send alternate authentication information to the server."
+ (let ((pass pop3-password))
+ (if (and pop3-password-required (not pass))
+ (setq pass
+ (read-passwd (format "Password for %s: " pop3-maildrop))))
+ (if pass
+ (let ((hash (md5 (concat pop3-timestamp pass) nil nil 'binary)))
+ (pop3-send-command process (format "APOP %s %s" user hash))
+ (let ((response (pop3-read-response process t)))
+ (if (not (and response (string-match "+OK" response)))
+ (pop3-quit process)))))
+ ))
+
+;; TRANSACTION STATE
+
+(defun pop3-stat (process)
+ "Return the number of messages in the maildrop and the maildrop's size."
+ (pop3-send-command process "STAT")
+ (let ((response (pop3-read-response process t)))
+ (list (string-to-number (nth 1 (split-string response " ")))
+ (string-to-number (nth 2 (split-string response " "))))
+ ))
+
+(defun pop3-list (process &optional msg)
+ "If MSG is nil, return an alist of (MESSAGE-ID . SIZE) pairs.
+Otherwise, return the size of the message-id MSG"
+ (pop3-send-command process (if msg
+ (format "LIST %d" msg)
+ "LIST"))
+ (let ((response (pop3-read-response process t)))
+ (if msg
+ (string-to-number (nth 2 (split-string response " ")))
+ (let ((start pop3-read-point) end)
+ (with-current-buffer (process-buffer process)
+ (while (not (re-search-forward "^\\.\r\n" nil t))
+ (pop3-accept-process-output process)
+ (goto-char start))
+ (setq pop3-read-point (point-marker))
+ (goto-char (match-beginning 0))
+ (setq end (point-marker))
+ (mapcar #'(lambda (s) (let ((split (split-string s " ")))
+ (cons (string-to-number (nth 0 split))
+ (string-to-number (nth 1 split)))))
+ (split-string (buffer-substring start end) "\r\n" t)))))))
+
+(defun pop3-retr (process msg crashbuf)
+ "Retrieve message-id MSG to buffer CRASHBUF."
+ (pop3-send-command process (format "RETR %s" msg))
+ (pop3-read-response process)
+ (let ((start pop3-read-point) end)
+ (with-current-buffer (process-buffer process)
+ (while (not (re-search-forward "^\\.\r\n" nil t))
+ (unless (memq (process-status process) '(open run))
+ (error "pop3 server closed the connection"))
+ (pop3-accept-process-output process)
+ (goto-char start))
+ (setq pop3-read-point (point-marker))
+ ;; this code does not seem to work for some POP servers...
+ ;; and I cannot figure out why not.
+ ;; (goto-char (match-beginning 0))
+ ;; (backward-char 2)
+ ;; (if (not (looking-at "\r\n"))
+ ;; (insert "\r\n"))
+ ;; (re-search-forward "\\.\r\n")
+ (goto-char (match-beginning 0))
+ (setq end (point-marker))
+ (pop3-clean-region start end)
+ (pop3-munge-message-separator start end)
+ (with-current-buffer crashbuf
+ (erase-buffer))
+ (copy-to-buffer crashbuf start end)
+ (delete-region start end)
+ )))
+
+(defun pop3-dele (process msg)
+ "Mark message-id MSG as deleted."
+ (pop3-send-command process (format "DELE %s" msg))
+ (pop3-read-response process))
+
+(defun pop3-noop (process msg)
+ "No-operation."
+ (pop3-send-command process "NOOP")
+ (pop3-read-response process))
+
+(defun pop3-last (process)
+ "Return highest accessed message-id number for the session."
+ (pop3-send-command process "LAST")
+ (let ((response (pop3-read-response process t)))
+ (string-to-number (nth 1 (split-string response " ")))
+ ))
+
+(defun pop3-rset (process)
+ "Remove all delete marks from current maildrop."
+ (pop3-send-command process "RSET")
+ (pop3-read-response process))
+
+;; UPDATE
+
+(defun pop3-quit (process)
+ "Close connection to POP3 server.
+Tell server to remove all messages marked as deleted, unlock the maildrop,
+and close the connection."
+ (pop3-send-command process "QUIT")
+ (pop3-read-response process t)
+ (if process
+ (with-current-buffer (process-buffer process)
+ (goto-char (point-max))
+ (delete-process process))))
+
+;; Summary of POP3 (Post Office Protocol version 3) commands and responses
+
+;;; AUTHORIZATION STATE
+
+;; Initial TCP connection
+;; Arguments: none
+;; Restrictions: none
+;; Possible responses:
+;; +OK [POP3 server ready]
+
+;; USER name
+;; Arguments: a server specific user-id (required)
+;; Restrictions: authorization state [after unsuccessful USER or PASS
+;; Possible responses:
+;; +OK [valid user-id]
+;; -ERR [invalid user-id]
+
+;; PASS string
+;; Arguments: a server/user-id specific password (required)
+;; Restrictions: authorization state, after successful USER
+;; Possible responses:
+;; +OK [maildrop locked and ready]
+;; -ERR [invalid password]
+;; -ERR [unable to lock maildrop]
+
+;; STLS (RFC 2595)
+;; Arguments: none
+;; Restrictions: Only permitted in AUTHORIZATION state.
+;; Possible responses:
+;; +OK
+;; -ERR
+
+;;; TRANSACTION STATE
+
+;; STAT
+;; Arguments: none
+;; Restrictions: transaction state
+;; Possible responses:
+;; +OK nn mm [# of messages, size of maildrop]
+
+;; LIST [msg]
+;; Arguments: a message-id (optional)
+;; Restrictions: transaction state; msg must not be deleted
+;; Possible responses:
+;; +OK [scan listing follows]
+;; -ERR [no such message]
+
+;; RETR msg
+;; Arguments: a message-id (required)
+;; Restrictions: transaction state; msg must not be deleted
+;; Possible responses:
+;; +OK [message contents follow]
+;; -ERR [no such message]
+
+;; DELE msg
+;; Arguments: a message-id (required)
+;; Restrictions: transaction state; msg must not be deleted
+;; Possible responses:
+;; +OK [message deleted]
+;; -ERR [no such message]
+
+;; NOOP
+;; Arguments: none
+;; Restrictions: transaction state
+;; Possible responses:
+;; +OK
+
+;; LAST
+;; Arguments: none
+;; Restrictions: transaction state
+;; Possible responses:
+;; +OK nn [highest numbered message accessed]
+
+;; RSET
+;; Arguments: none
+;; Restrictions: transaction state
+;; Possible responses:
+;; +OK [all delete marks removed]
+
+;; UIDL [msg]
+;; Arguments: a message-id (optional)
+;; Restrictions: transaction state; msg must not be deleted
+;; Possible responses:
+;; +OK [uidl listing follows]
+;; -ERR [no such message]
+
+;;; UPDATE STATE
+
+;; QUIT
+;; Arguments: none
+;; Restrictions: none
+;; Possible responses:
+;; +OK [TCP connection closed]
+
+(provide 'pop3)
+
+;;; pop3.el ends here
diff --git a/lisp/net/puny.el b/lisp/net/puny.el
new file mode 100644
index 00000000000..50bde85287d
--- /dev/null
+++ b/lisp/net/puny.el
@@ -0,0 +1,248 @@
+;;; puny.el --- translate non-ASCII domain names to ASCII
+
+;; Copyright (C) 2015-2016 Free Software Foundation, Inc.
+
+;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
+;; Keywords: mail, net
+
+;; 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 3 of the License, 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. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Written by looking at
+;; http://stackoverflow.com/questions/183485/can-anyone-recommend-a-good-free-javascript-for-punycode-to-unicode-conversion
+
+;;; Code:
+
+(require 'seq)
+
+(defun puny-encode-domain (domain)
+ "Encode DOMAIN according to the IDNA/punycode algorithm.
+For instance, \"fśf.org\" => \"xn--ff-2sa.org\"."
+ ;; The vast majority of domain names are not IDNA domain names, so
+ ;; add a check first to avoid doing unnecessary work.
+ (if (string-match "\\'[[:ascii:]]+\\'" domain)
+ domain
+ (mapconcat 'puny-encode-string (split-string domain "[.]") ".")))
+
+(defun puny-encode-string (string)
+ "Encode STRING according to the IDNA/punycode algorithm.
+This is used to encode non-ASCII domain names.
+For instance, \"bücher\" => \"xn--bcher-kva\"."
+ (let ((ascii (seq-filter (lambda (char)
+ (< char 128))
+ string)))
+ (if (= (length ascii) (length string))
+ string
+ (concat "xn--"
+ (if (null ascii)
+ ""
+ (concat ascii "-"))
+ (puny-encode-complex (length ascii) string)))))
+
+(defun puny-decode-domain (domain)
+ "Decode DOMAIN according to the IDNA/punycode algorithm.
+For instance, \"xn--ff-2sa.org\" => \"fśf.org\"."
+ (mapconcat 'puny-decode-string (split-string domain "[.]") "."))
+
+(defun puny-decode-string (string)
+ "Decode an IDNA/punycode-encoded string.
+For instance \"xn--bcher-kva\" => \"bücher\"."
+ (if (string-match "\\`xn--" string)
+ (puny-decode-string-internal (substring string 4))
+ string))
+
+(defconst puny-initial-n 128)
+(defconst puny-initial-bias 72)
+(defconst puny-base 36)
+(defconst puny-damp 700)
+(defconst puny-tmin 1)
+(defconst puny-tmax 26)
+(defconst puny-skew 28)
+
+;; 0-25 a-z
+;; 26-36 0-9
+(defun puny-encode-digit (d)
+ (if (< d 26)
+ (+ ?a d)
+ (+ ?0 (- d 26))))
+
+(defun puny-adapt (delta num-points first-time)
+ (let ((delta (if first-time
+ (/ delta puny-damp)
+ (/ delta 2)))
+ (k 0))
+ (setq delta (+ delta (/ delta num-points)))
+ (while (> delta (/ (* (- puny-base puny-tmin)
+ puny-tmax)
+ 2))
+ (setq delta (/ delta (- puny-base puny-tmin))
+ k (+ k puny-base)))
+ (+ k (/ (* (1+ (- puny-base puny-tmin)) delta)
+ (+ delta puny-skew)))))
+
+(defun puny-encode-complex (insertion-points string)
+ (let ((n puny-initial-n)
+ (delta 0)
+ (bias puny-initial-bias)
+ (h insertion-points)
+ result m ijv q)
+ (while (< h (length string))
+ (setq ijv (cl-loop for char across string
+ when (>= char n)
+ minimize char))
+ (setq m ijv)
+ (setq delta (+ delta (* (- m n) (+ h 1)))
+ n m)
+ (cl-loop for char across string
+ when (< char n)
+ do (cl-incf delta)
+ when (= char ijv)
+ do (progn
+ (setq q delta)
+ (cl-loop with k = puny-base
+ for t1 = (cond
+ ((<= k bias)
+ puny-tmin)
+ ((>= k (+ bias puny-tmax))
+ puny-tmax)
+ (t
+ (- k bias)))
+ while (>= q t1)
+ do (push (puny-encode-digit
+ (+ t1 (mod (- q t1)
+ (- puny-base t1))))
+ result)
+ do (setq q (/ (- q t1) (- puny-base t1))
+ k (+ k puny-base)))
+ (push (puny-encode-digit q) result)
+ (setq bias (puny-adapt delta (+ h 1) (= h insertion-points))
+ delta 0
+ h (1+ h))))
+ (cl-incf delta)
+ (cl-incf n))
+ (nreverse result)))
+
+(defun puny-decode-digit (cp)
+ (cond
+ ((<= cp ?9)
+ (+ (- cp ?0) 26))
+ ((<= cp ?Z)
+ (- cp ?A))
+ ((<= cp ?z)
+ (- cp ?a))
+ (t
+ puny-base)))
+
+(defun puny-decode-string-internal (string)
+ (with-temp-buffer
+ (insert string)
+ (goto-char (point-max))
+ (search-backward "-" nil (point-min))
+ ;; The encoded chars are after the final dash.
+ (let ((encoded (buffer-substring (1+ (point)) (point-max)))
+ (ic 0)
+ (i 0)
+ (bias puny-initial-bias)
+ (n puny-initial-n)
+ out)
+ (delete-region (point) (point-max))
+ (while (< ic (length encoded))
+ (let ((old-i i)
+ (w 1)
+ (k puny-base)
+ digit t1)
+ (cl-loop do (progn
+ (setq digit (puny-decode-digit (aref encoded ic)))
+ (cl-incf ic)
+ (cl-incf i (* digit w))
+ (setq t1 (cond
+ ((<= k bias)
+ puny-tmin)
+ ((>= k (+ bias puny-tmax))
+ puny-tmax)
+ (t
+ (- k bias)))))
+ while (>= digit t1)
+ do (setq w (* w (- puny-base t1))
+ k (+ k puny-base)))
+ (setq out (1+ (buffer-size)))
+ (setq bias (puny-adapt (- i old-i) out (= old-i 0))))
+
+ (setq n (+ n (/ i out))
+ i (mod i out))
+ (goto-char (point-min))
+ (forward-char i)
+ (insert (format "%c" n))
+ (cl-incf i)))
+ (buffer-string)))
+
+;; http://www.unicode.org/reports/tr39/#Restriction_Level_Detection
+;; http://www.unicode.org/reports/tr31/#Table_Candidate_Characters_for_Inclusion_in_Identifiers
+
+(defun puny-highly-restrictive-string-p (string)
+ "Say whether STRING is \"highly restrictive\" in the Unicode IDNA sense.
+See http://www.unicode.org/reports/tr39/#Restriction_Level_Detection
+for details. The main idea is that if you're mixing
+scripts (like latin and cyrillic), you may confuse the user by
+using homographs."
+ (let ((scripts
+ (delq
+ t
+ (seq-uniq
+ (seq-map (lambda (char)
+ (if (memq char
+ ;; These characters are always allowed
+ ;; in any string.
+ '(#x0027 ; APOSTROPHE
+ #x002D ; HYPHEN-MINUS
+ #x002E ; FULL STOP
+ #x003A ; COLON
+ #x00B7 ; MIDDLE DOT
+ #x058A ; ARMENIAN HYPHEN
+ #x05F3 ; HEBREW PUNCTUATION GERESH
+ #x05F4 ; HEBREW PUNCTUATION GERSHAYIM
+ #x0F0B ; TIBETAN MARK INTERSYLLABIC TSHEG
+ #x200C ; ZERO WIDTH NON-JOINER*
+ #x200D ; ZERO WIDTH JOINER*
+ #x2010 ; HYPHEN
+ #x2019 ; RIGHT SINGLE QUOTATION MARK
+ #x2027 ; HYPHENATION POINT
+ #x30A0 ; KATAKANA-HIRAGANA DOUBLE HYPHEN
+ #x30FB)) ; KATAKANA MIDDLE DOT
+ t
+ (aref char-script-table char)))
+ string)))))
+ (or
+ ;; Every character uses the same script.
+ (= (length scripts) 1)
+ (seq-some 'identity
+ (mapcar (lambda (list)
+ (seq-every-p (lambda (script)
+ (memq script list))
+ scripts))
+ '((latin han hiragana kana)
+ (latin han bopomofo)
+ (latin han hangul)))))))
+
+(defun puny-highly-restrictive-domain-p (domain)
+ "Say whether DOMAIN is \"highly restrictive\" in the Unicode IDNA sense.
+See `puny-highly-restrictive-string-p' for further details."
+ (seq-every-p 'puny-highly-restrictive-string-p (split-string domain "[.]")))
+
+(provide 'puny)
+
+;;; puny.el ends here
diff --git a/lisp/net/quickurl.el b/lisp/net/quickurl.el
index bb9ce31307b..773589af47e 100644
--- a/lisp/net/quickurl.el
+++ b/lisp/net/quickurl.el
@@ -101,17 +101,12 @@
:type 'file
:group 'quickurl)
-(defcustom quickurl-format-function (lambda (url) (format "<URL:%s>" (quickurl-url-url url)))
+(defcustom quickurl-format-function #'quickurl-format-url
"Function to format the URL before insertion into the current buffer."
:type 'function
:group 'quickurl)
-(defcustom quickurl-sort-function (lambda (list)
- (sort list
- (lambda (x y)
- (string<
- (downcase (quickurl-url-description x))
- (downcase (quickurl-url-description y))))))
+(defcustom quickurl-sort-function #'quickurl-sort-urls
"Function to sort the URL list."
:type 'function
:group 'quickurl)
@@ -175,7 +170,6 @@ in your init file (after loading/requiring quickurl).")
(defvar quickurl-list-mode-map
(let ((map (make-sparse-keymap)))
- (suppress-keymap map t)
(define-key map "a" #'quickurl-list-add-url)
(define-key map [(control m)] #'quickurl-list-insert-url)
(define-key map "u" #'quickurl-list-insert-naked-url)
@@ -185,7 +179,6 @@ in your init file (after loading/requiring quickurl).")
(define-key map [(control g)] #'quickurl-list-quit)
(define-key map "q" #'quickurl-list-quit)
(define-key map [mouse-2] #'quickurl-list-mouse-select)
- (define-key map "?" #'describe-mode)
map)
"Local keymap for a `quickurl-list-mode' buffer.")
@@ -253,7 +246,18 @@ returned."
;; Main code:
-(cl-defun quickurl-read (&optional buffer)
+(defun quickurl-format-url (url)
+ (format "<URL:%s>" (quickurl-url-url url)))
+
+(defun quickurl-sort-urls (list)
+ "Sort URLs in LIST according to their `quickurl-url-description'."
+ (sort list
+ (lambda (x y)
+ (string<
+ (downcase (quickurl-url-description x))
+ (downcase (quickurl-url-description y))))))
+
+(defun quickurl-read (&optional buffer)
"`read' the URL list from BUFFER into `quickurl-urls'.
BUFFER, if nil, defaults to current buffer.
@@ -298,7 +302,7 @@ Also display a `message' saying what the URL was unless SILENT is non-nil."
(message "Found %s" (quickurl-url-url url))))
;;;###autoload
-(cl-defun quickurl (&optional lookup)
+(defun quickurl (&optional lookup)
"Insert a URL based on LOOKUP.
If not supplied LOOKUP is taken to be the word at point in the current
@@ -427,17 +431,14 @@ current buffer, this default action can be modified via
;; quickurl-list mode.
-(put 'quickurl-list-mode 'mode-class 'special)
-
;;;###autoload
-(define-derived-mode quickurl-list-mode fundamental-mode "quickurl list"
+(define-derived-mode quickurl-list-mode special-mode "Quickurl"
"A mode for browsing the quickurl URL list.
The key bindings for `quickurl-list-mode' are:
\\{quickurl-list-mode-map}"
- (setq buffer-read-only t
- truncate-lines t))
+ (setq truncate-lines t))
;;;###autoload
(defun quickurl-list ()
@@ -459,14 +460,13 @@ The key bindings for `quickurl-list-mode' are:
(fmt (format "%%-%ds %%s\n" (apply #'max sizes)))
(inhibit-read-only t))
(erase-buffer)
- (cl-loop for url in quickurl-urls
- do (let ((start (point)))
- (insert (format fmt (quickurl-url-description url)
- (quickurl-url-url url)))
- (add-text-properties
- start (1- (point))
- '(mouse-face highlight
- help-echo "mouse-2: insert this URL"))))
+ (dolist (url quickurl-urls)
+ (let ((start (point)))
+ (insert (format fmt (quickurl-url-description url)
+ (quickurl-url-url url)))
+ (add-text-properties
+ start (1- (point))
+ '(mouse-face highlight help-echo "mouse-2: insert this URL"))))
(goto-char (point-min)))))
(defun quickurl-list-add-url (word url comment)
@@ -477,9 +477,7 @@ The key bindings for `quickurl-list-mode' are:
(defun quickurl-list-quit ()
"Kill the buffer named `quickurl-list-buffer-name'."
(interactive)
- (kill-buffer quickurl-list-buffer-name)
- (switch-to-buffer quickurl-list-last-buffer)
- (delete-other-windows))
+ (quit-window t))
(defun quickurl-list-mouse-select (event)
"Select the URL under the mouse click."
diff --git a/lisp/net/rcirc.el b/lisp/net/rcirc.el
index 55b43f63963..66e6326085c 100644
--- a/lisp/net/rcirc.el
+++ b/lisp/net/rcirc.el
@@ -103,7 +103,12 @@ connected to automatically.
`:encryption'
VALUE must be `plain' (the default) for unencrypted connections, or `tls'
-for connections using SSL/TLS."
+for connections using SSL/TLS.
+
+`:server-alias'
+
+VALUE must be a string that will be used instead of the server name for
+display purposes. If absent, the real server name will be displayed instead."
:type '(alist :key-type string
:value-type (plist :options
((:nick string)
@@ -113,7 +118,8 @@ for connections using SSL/TLS."
(:full-name string)
(:channels (repeat string))
(:encryption (choice (const tls)
- (const plain))))))
+ (const plain)))
+ (:server-alias string))))
:group 'rcirc)
(defcustom rcirc-default-port 6667
@@ -484,22 +490,26 @@ If ARG is non-nil, instead prompt for connection parameters."
(channels (plist-get (cdr c) :channels))
(password (plist-get (cdr c) :password))
(encryption (plist-get (cdr c) :encryption))
+ (server-alias (plist-get (cdr c) :server-alias))
contact)
(when server
(let (connected)
(dolist (p (rcirc-process-list))
- (when (string= server (process-name p))
+ (when (string= (or server-alias server) (process-name p))
(setq connected p)))
(if (not connected)
(condition-case nil
(rcirc-connect server port nick user-name
- full-name channels password encryption)
- (quit (message "Quit connecting to %s" server)))
+ full-name channels password encryption
+ server-alias)
+ (quit (message "Quit connecting to %s"
+ (or server-alias server))))
(with-current-buffer (process-buffer connected)
(setq contact (process-contact
- (get-buffer-process (current-buffer)) :host))
+ (get-buffer-process (current-buffer)) :name))
(setq connected-servers
- (cons (if (stringp contact) contact server)
+ (cons (if (stringp contact)
+ contact (or server-alias server))
connected-servers))))))))
(when connected-servers
(message "Already connected to %s"
@@ -528,9 +538,10 @@ If ARG is non-nil, instead prompt for connection parameters."
;;;###autoload
(defun rcirc-connect (server &optional port nick user-name
- full-name startup-channels password encryption)
+ full-name startup-channels password encryption
+ server-alias)
(save-excursion
- (message "Connecting to %s..." server)
+ (message "Connecting to %s..." (or server-alias server))
(let* ((inhibit-eol-conversion)
(port-number (if port
(if (stringp port)
@@ -542,7 +553,7 @@ If ARG is non-nil, instead prompt for connection parameters."
(full-name (or full-name rcirc-default-full-name))
(startup-channels startup-channels)
(process (open-network-stream
- server nil server port-number
+ (or server-alias server) nil server port-number
:type (or encryption 'plain))))
;; set up process
(set-process-coding-system process 'raw-text 'raw-text)
@@ -557,7 +568,8 @@ If ARG is non-nil, instead prompt for connection parameters."
password encryption))
(setq-local rcirc-process process)
(setq-local rcirc-server server)
- (setq-local rcirc-server-name server) ; Update when we get 001 response.
+ (setq-local rcirc-server-name
+ (or server-alias server)) ; Update when we get 001 response.
(setq-local rcirc-buffer-alist nil)
(setq-local rcirc-nick-table (make-hash-table :test 'equal))
(setq-local rcirc-nick nick)
@@ -584,7 +596,7 @@ If ARG is non-nil, instead prompt for connection parameters."
(setq rcirc-keepalive-timer
(run-at-time 0 (/ rcirc-timeout-seconds 2) 'rcirc-keepalive)))
- (message "Connecting to %s...done" server)
+ (message "Connecting to %s...done" (or server-alias server))
;; return process object
process)))
@@ -599,10 +611,7 @@ If ARG is non-nil, instead prompt for connection parameters."
`(with-current-buffer rcirc-server-buffer
,@body))
-(defalias 'rcirc-float-time
- (if (featurep 'xemacs)
- 'time-to-seconds
- 'float-time))
+(define-obsolete-function-alias 'rcirc-float-time 'float-time "26.1")
(defun rcirc-prompt-for-encryption (server-plist)
"Prompt the user for the encryption method to use.
@@ -626,7 +635,7 @@ last ping."
(rcirc-send-ctcp process
rcirc-nick
(format "KEEPALIVE %f"
- (rcirc-float-time))))))
+ (float-time))))))
(rcirc-process-list))
;; no processes, clean up timer
(when (timerp rcirc-keepalive-timer)
@@ -635,7 +644,7 @@ last ping."
(defun rcirc-handler-ctcp-KEEPALIVE (process _target _sender message)
(with-rcirc-process-buffer process
- (setq header-line-format (format "%f" (- (rcirc-float-time)
+ (setq header-line-format (format "%f" (- (float-time)
(string-to-number message))))))
(defvar rcirc-debug-buffer "*rcirc debug*")
@@ -2330,7 +2339,7 @@ With a prefix arg, prompt for new topic."
(defun rcirc-ctcp-sender-PING (process target _request)
"Send a CTCP PING message to TARGET."
- (let ((timestamp (format "%.0f" (rcirc-float-time))))
+ (let ((timestamp (format "%.0f" (float-time))))
(rcirc-send-ctcp process target "PING" timestamp)))
(defun rcirc-cmd-me (args &optional process target)
diff --git a/lisp/net/secrets.el b/lisp/net/secrets.el
index 55d5f007ac5..ea26a521afd 100644
--- a/lisp/net/secrets.el
+++ b/lisp/net/secrets.el
@@ -1,4 +1,4 @@
-;;; secrets.el --- Client interface to gnome-keyring and kwallet.
+;;; secrets.el --- Client interface to gnome-keyring and kwallet. -*- lexical-binding: t -*-
;; Copyright (C) 2010-2016 Free Software Foundation, Inc.
@@ -433,7 +433,7 @@ returned, and it will be stored in `secrets-session-path'."
"Handler for signals emitted by `secrets-interface-service'."
(cond
((string-equal (dbus-event-member-name last-input-event) "CollectionCreated")
- (add-to-list 'secrets-collection-paths (car args)))
+ (cl-pushnew (car args) secrets-collection-paths))
((string-equal (dbus-event-member-name last-input-event) "CollectionDeleted")
(setq secrets-collection-paths
(delete (car args) secrets-collection-paths)))))
@@ -610,12 +610,11 @@ The object labels of the found items are returned as list."
(error 'wrong-type-argument (car attributes)))
(unless (stringp (cadr attributes))
(error 'wrong-type-argument (cadr attributes)))
- (setq props (add-to-list
- 'props
+ (setq props (append
+ props
(list :dict-entry
(substring (symbol-name (car attributes)) 1)
- (cadr attributes))
- 'append)
+ (cadr attributes)))
attributes (cddr attributes)))
;; Search. The result is a list of object paths.
(setq result
@@ -649,12 +648,11 @@ The object path of the created item is returned."
(error 'wrong-type-argument (car attributes)))
(unless (stringp (cadr attributes))
(error 'wrong-type-argument (cadr attributes)))
- (setq props (add-to-list
- 'props
+ (setq props (append
+ props
(list :dict-entry
(substring (symbol-name (car attributes)) 1)
- (cadr attributes))
- 'append)
+ (cadr attributes)))
attributes (cddr attributes)))
;; Create the item.
(setq result
@@ -734,33 +732,30 @@ If there is no such item, or the item doesn't own this attribute, return nil."
;;; Visualization.
-(define-derived-mode secrets-mode nil "Secrets"
+(defvar secrets-mode-map
+ (let ((map (make-sparse-keymap)))
+ (set-keymap-parent map (make-composed-keymap special-mode-map widget-keymap))
+ (define-key map "n" 'next-line)
+ (define-key map "p" 'previous-line)
+ (define-key map "z" 'kill-this-buffer)
+ map)
+ "Keymap used in `secrets-mode' buffers.")
+
+(define-derived-mode secrets-mode special-mode "Secrets"
"Major mode for presenting password entries retrieved by Security Service.
In this mode, widgets represent the search results.
\\{secrets-mode-map}"
- ;; Keymap.
- (setq secrets-mode-map (copy-keymap special-mode-map))
- (set-keymap-parent secrets-mode-map widget-keymap)
- (define-key secrets-mode-map "z" 'kill-this-buffer)
-
+ (setq buffer-undo-list t)
+ (set (make-local-variable 'revert-buffer-function)
+ #'secrets-show-collections)
;; When we toggle, we must set temporary widgets.
(set (make-local-variable 'tree-widget-after-toggle-functions)
- '(secrets-tree-widget-after-toggle-function))
-
- (when (not (called-interactively-p 'interactive))
- ;; Initialize buffer.
- (setq buffer-read-only t)
- (let ((inhibit-read-only t))
- (erase-buffer))))
+ '(secrets-tree-widget-after-toggle-function)))
;; It doesn't make sense to call it interactively.
(put 'secrets-mode 'disabled t)
-;; The very first buffer created with `secrets-mode' does not have the
-;; keymap etc. So we create a dummy buffer. Stupid.
-(with-temp-buffer (secrets-mode))
-
;; We autoload `secrets-show-secrets' only on systems with D-Bus support.
;;;###autoload(when (featurep 'dbusbind)
;;;###autoload (autoload 'secrets-show-secrets "secrets" nil t))
@@ -783,10 +778,9 @@ to their attributes."
(secrets-mode)
(secrets-show-collections))))
-(defun secrets-show-collections ()
+(defun secrets-show-collections (&optional _ignore _noconfirm)
"Show all available collections."
- (let ((inhibit-read-only t)
- (alias (secrets-get-alias "default")))
+ (let ((inhibit-read-only t))
(erase-buffer)
(tree-widget-set-theme "folder")
(dolist (coll (secrets-list-collections))
@@ -855,7 +849,7 @@ to their attributes."
"%v\n"))))
attributes))))
-(defun secrets-tree-widget-after-toggle-function (widget &rest ignore)
+(defun secrets-tree-widget-after-toggle-function (widget &rest _ignore)
"Add a temporary widget to show the password."
(dolist (child (widget-get widget :children))
(when (widget-member child :secret)
@@ -867,7 +861,7 @@ to their attributes."
"Show password")))
(widget-setup))
-(defun secrets-tree-widget-show-password (widget &rest ignore)
+(defun secrets-tree-widget-show-password (widget &rest _ignore)
"Show password, and remove temporary widget."
(let ((parent (widget-get widget :parent)))
(widget-put parent :secret nil)
diff --git a/lisp/net/shr.el b/lisp/net/shr.el
index 18bc7b86715..9ea143da335 100644
--- a/lisp/net/shr.el
+++ b/lisp/net/shr.el
@@ -1,4 +1,4 @@
-;;; shr.el --- Simple HTML Renderer
+;;; shr.el --- Simple HTML Renderer -*- lexical-binding: t -*-
;; Copyright (C) 2010-2016 Free Software Foundation, Inc.
@@ -36,6 +36,8 @@
(require 'subr-x)
(require 'dom)
(require 'seq)
+(require 'svg)
+(require 'image)
(defgroup shr nil
"Simple HTML Renderer"
@@ -64,6 +66,12 @@ fit these criteria."
:group 'shr
:type 'boolean)
+(defcustom shr-use-colors t
+ "If non-nil, respect color specifications in the HTML."
+ :version "26.1"
+ :group 'shr
+ :type 'boolean)
+
(defcustom shr-table-horizontal-line nil
"Character used to draw horizontal table lines.
If nil, don't draw horizontal table lines."
@@ -136,6 +144,14 @@ cid: URL as the argument.")
(defvar shr-inhibit-images nil
"If non-nil, inhibit loading images.")
+(defvar shr-external-rendering-functions nil
+ "Alist of tag/function pairs used to alter how shr renders certain tags.
+For instance, eww uses this to alter rendering of title, forms
+and other things:
+((title . eww-tag-title)
+ (form . eww-tag-form)
+ ...)")
+
;;; Internal variables.
(defvar shr-folding-mode nil)
@@ -151,7 +167,6 @@ cid: URL as the argument.")
(defvar shr-depth 0)
(defvar shr-warning nil)
(defvar shr-ignore-cache nil)
-(defvar shr-external-rendering-functions nil)
(defvar shr-target-id nil)
(defvar shr-table-separator-length 1)
(defvar shr-table-separator-pixel-width 0)
@@ -172,10 +187,16 @@ cid: URL as the argument.")
(define-key map "w" 'shr-copy-url)
(define-key map "u" 'shr-copy-url)
(define-key map "v" 'shr-browse-url)
- (define-key map "o" 'shr-save-contents)
+ (define-key map "O" 'shr-save-contents)
(define-key map "\r" 'shr-browse-url)
map))
+(defvar shr-image-map
+ (let ((map (copy-keymap shr-map)))
+ (when (boundp 'image-map)
+ (set-keymap-parent map image-map))
+ map))
+
;; Public functions and commands.
(declare-function libxml-parse-html-region "xml.c"
(start end &optional base-url discard-comments))
@@ -254,22 +275,19 @@ DOM should be a parse tree as generated by
(set-window-hscroll nil 0)
(shr-descend dom)
(shr-fill-lines start (point))
- (shr-remove-trailing-whitespace start (point))
+ (shr--remove-blank-lines-at-the-end start (point))
(when shr-warning
(message "%s" shr-warning))))
-(defun shr-remove-trailing-whitespace (start end)
- (let ((width (window-width)))
- (save-restriction
+(defun shr--remove-blank-lines-at-the-end (start end)
+ (save-restriction
+ (save-excursion
(narrow-to-region start end)
- (goto-char start)
- (while (not (eobp))
- (end-of-line)
- (when (> (shr-previous-newline-padding-width (current-column)) width)
- (dolist (overlay (overlays-at (point)))
- (when (overlay-get overlay 'before-string)
- (overlay-put overlay 'before-string nil))))
- (forward-line 1)))))
+ (goto-char end)
+ (when (and (re-search-backward "[^ \n]" nil t)
+ (not (eobp)))
+ (forward-line 1)
+ (delete-region (point) (point-max))))))
(defun shr-copy-url (&optional image-url)
"Copy the URL under point to the kill ring.
@@ -279,8 +297,10 @@ image under point instead.
If called twice, then try to fetch the URL and see whether it
redirects somewhere else."
(interactive "P")
- (let ((url (or (get-text-property (point) 'shr-url)
- (get-text-property (point) 'image-url))))
+ (let ((url (if image-url
+ (get-text-property (point) 'image-url)
+ (or (get-text-property (point) 'shr-url)
+ (get-text-property (point) 'image-url)))))
(cond
((not url)
(message "No URL under point"))
@@ -435,11 +455,10 @@ size, and full-buffer size."
(defun shr-descend (dom)
(let ((function
- (or
- ;; Allow other packages to override (or provide) rendering
- ;; of elements.
- (cdr (assq (dom-tag dom) shr-external-rendering-functions))
- (intern (concat "shr-tag-" (symbol-name (dom-tag dom))) obarray)))
+ (intern (concat "shr-tag-" (symbol-name (dom-tag dom))) obarray))
+ ;; Allow other packages to override (or provide) rendering
+ ;; of elements.
+ (external (cdr (assq (dom-tag dom) shr-external-rendering-functions)))
(style (dom-attr dom 'style))
(shr-stylesheet shr-stylesheet)
(shr-depth (1+ shr-depth))
@@ -454,9 +473,12 @@ size, and full-buffer size."
(setq style nil)))
;; If we have a display:none, then just ignore this part of the DOM.
(unless (equal (cdr (assq 'display shr-stylesheet)) "none")
- (if (fboundp function)
- (funcall function dom)
- (shr-generic dom))
+ (cond (external
+ (funcall external dom))
+ ((fboundp function)
+ (funcall function dom))
+ (t
+ (shr-generic dom)))
(when (and shr-target-id
(equal (dom-attr dom 'id) shr-target-id))
;; If the element was empty, we don't have anything to put the
@@ -538,6 +560,16 @@ size, and full-buffer size."
(insert string)
(shr-pixel-column))))
+(defsubst shr--translate-insertion-chars ()
+ ;; Remove soft hyphens.
+ (goto-char (point-min))
+ (while (search-forward "­" nil t)
+ (replace-match "" t t))
+ ;; Translate non-breaking spaces into real spaces.
+ (goto-char (point-min))
+ (while (search-forward " " nil t)
+ (replace-match " " t t)))
+
(defun shr-insert (text)
(when (and (not (bolp))
(get-text-property (1- (point)) 'image-url))
@@ -548,14 +580,11 @@ size, and full-buffer size."
(insert text)
(save-restriction
(narrow-to-region start (point))
- ;; Remove soft hyphens.
- (goto-char (point-min))
- (while (search-forward "­" nil t)
- (replace-match "" t t))
+ (shr--translate-insertion-chars)
(goto-char (point-max)))))
(t
(let ((font-start (point)))
- (when (and (string-match "\\`[ \t\n\r ]" text)
+ (when (and (string-match "\\`[ \t\n\r]" text)
(not (bolp))
(not (eq (char-after (1- (point))) ? )))
(insert " "))
@@ -565,14 +594,11 @@ size, and full-buffer size."
(save-restriction
(narrow-to-region start (point))
(goto-char start)
- (when (looking-at "[ \t\n\r ]+")
+ (when (looking-at "[ \t\n\r]+")
(replace-match "" t t))
- (while (re-search-forward "[ \t\n\r ]+" nil t)
+ (while (re-search-forward "[ \t\n\r]+" nil t)
(replace-match " " t t))
- ;; Remove soft hyphens.
- (goto-char (point-min))
- (while (search-forward "­" nil t)
- (replace-match "" t t))
+ (shr--translate-insertion-chars)
(goto-char (point-max)))
;; We may have removed everything we inserted if if was just
;; spaces.
@@ -639,13 +665,12 @@ size, and full-buffer size."
;; Success; continue.
(when (= (preceding-char) ?\s)
(delete-char -1))
- (let ((face (get-text-property (point) 'face))
- (background-start (point)))
+ (let ((props (text-properties-at (point)))
+ (gap-start (point)))
(insert "\n")
(shr-indent)
- (when face
- (put-text-property background-start (point) 'face
- `,(shr-face-background face))))
+ (when props
+ (add-text-properties gap-start (point) props)))
(setq start (point))
(shr-vertical-motion shr-internal-width)
(when (looking-at " $")
@@ -766,11 +791,12 @@ size, and full-buffer size."
;; Strip leading whitespace
(and url (string-match "\\`\\s-+" url)
(setq url (substring url (match-end 0))))
- (cond ((or (not url)
- (not base)
+ (cond ((zerop (length url))
+ (nth 3 base))
+ ((or (not base)
(string-match "\\`[a-z]*:" url))
;; Absolute or empty URI
- (or url (nth 3 base)))
+ url)
((eq (aref url 0) ?/)
(if (and (> (length url) 1)
(eq (aref url 1) ?/))
@@ -955,10 +981,14 @@ element is the data blob and the second element is the content-type."
(create-image data 'svg t :ascent 100))
((eq size 'full)
(ignore-errors
- (shr-rescale-image data content-type)))
+ (shr-rescale-image data content-type
+ (plist-get flags :width)
+ (plist-get flags :height))))
(t
(ignore-errors
- (shr-rescale-image data content-type))))))
+ (shr-rescale-image data content-type
+ (plist-get flags :width)
+ (plist-get flags :height)))))))
(when image
;; When inserting big-ish pictures, put them at the
;; beginning of the line.
@@ -981,21 +1011,40 @@ element is the data blob and the second element is the content-type."
image)
(insert (or alt ""))))
-(defun shr-rescale-image (data &optional content-type)
- "Rescale DATA, if too big, to fit the current buffer."
- (if (not (and (fboundp 'imagemagick-types)
- (get-buffer-window (current-buffer))))
+(defun shr-rescale-image (data content-type width height)
+ "Rescale DATA, if too big, to fit the current buffer.
+WIDTH and HEIGHT are the sizes given in the HTML data, if any."
+ (if (or (not (fboundp 'imagemagick-types))
+ (not (get-buffer-window (current-buffer))))
(create-image data nil t :ascent 100)
- (let ((edges (window-inside-pixel-edges
- (get-buffer-window (current-buffer)))))
- (create-image
- data 'imagemagick t
- :ascent 100
- :max-width (truncate (* shr-max-image-proportion
- (- (nth 2 edges) (nth 0 edges))))
- :max-height (truncate (* shr-max-image-proportion
- (- (nth 3 edges) (nth 1 edges))))
- :format content-type))))
+ (let* ((edges (window-inside-pixel-edges
+ (get-buffer-window (current-buffer))))
+ (max-width (truncate (* shr-max-image-proportion
+ (- (nth 2 edges) (nth 0 edges)))))
+ (max-height (truncate (* shr-max-image-proportion
+ (- (nth 3 edges) (nth 1 edges)))))
+ (scaling (image-compute-scaling-factor image-scaling-factor)))
+ (when (or (and width
+ (> width max-width))
+ (and height
+ (> height max-height)))
+ (setq width nil
+ height nil))
+ (if (and width height
+ (< (* width scaling) max-width)
+ (< (* height scaling) max-height))
+ (create-image
+ data 'imagemagick t
+ :ascent 100
+ :width width
+ :height height
+ :format content-type)
+ (create-image
+ data 'imagemagick t
+ :ascent 100
+ :max-width max-width
+ :max-height max-height
+ :format content-type)))))
;; url-cache-extract autoloads url-cache.
(declare-function url-cache-create-filename "url-cache" (url))
@@ -1074,8 +1123,15 @@ START, and END. Note that START and END should be markers."
url)))
(if title (format "%s (%s)" iri title) iri))
'follow-link t
- 'mouse-face 'highlight
- 'keymap shr-map)))
+ 'mouse-face 'highlight))
+ ;; Don't overwrite any keymaps that are already in the buffer (i.e.,
+ ;; image keymaps).
+ (while (and start
+ (< start (point)))
+ (let ((next (next-single-property-change start 'keymap nil (point))))
+ (if (get-text-property start 'keymap)
+ (setq start next)
+ (put-text-property start (or next (point)) 'keymap shr-map)))))
(defun shr-encode-url (url)
"Encode URL."
@@ -1107,7 +1163,9 @@ ones, in case fg and bg are nil."
(shr-color-visible bg fg)))))))
(defun shr-colorize-region (start end fg &optional bg)
- (when (and (or fg bg) (>= (display-color-cells) 88))
+ (when (and shr-use-colors
+ (or fg bg)
+ (>= (display-color-cells) 88))
(let ((new-colors (shr-color-check fg bg)))
(when new-colors
(when fg
@@ -1120,18 +1178,6 @@ ones, in case fg and bg are nil."
t)))
new-colors)))
-(defun shr-previous-newline-padding-width (width)
- (let ((overlays (overlays-at (point)))
- (previous-width 0))
- (if (null overlays)
- width
- (dolist (overlay overlays)
- (setq previous-width
- (+ previous-width
- (length (plist-get (overlay-properties overlay)
- 'before-string)))))
- (+ width previous-width))))
-
;;; Tag-specific rendering rules.
(defun shr-tag-html (dom)
@@ -1140,7 +1186,9 @@ ones, in case fg and bg are nil."
((equal dir "ltr")
(setq bidi-paragraph-direction 'left-to-right))
((equal dir "rtl")
- (setq bidi-paragraph-direction 'right-to-left))))
+ (setq bidi-paragraph-direction 'right-to-left))
+ ((equal dir "auto")
+ (setq bidi-paragraph-direction nil))))
(shr-generic dom))
(defun shr-tag-body (dom)
@@ -1226,9 +1274,6 @@ ones, in case fg and bg are nil."
(defun shr-tag-s (dom)
(shr-fontize-dom dom 'shr-strike-through))
-(defun shr-tag-del (dom)
- (shr-fontize-dom dom 'shr-strike-through))
-
(defun shr-tag-b (dom)
(shr-fontize-dom dom 'bold))
@@ -1248,6 +1293,24 @@ ones, in case fg and bg are nil."
(let ((shr-current-font 'default))
(shr-generic dom)))
+(defun shr-tag-ins (cont)
+ (let* ((start (point))
+ (color "green")
+ (shr-stylesheet (nconc (list (cons 'color color))
+ shr-stylesheet)))
+ (shr-generic cont)
+ (shr-colorize-region start (point) color
+ (cdr (assq 'background-color shr-stylesheet)))))
+
+(defun shr-tag-del (cont)
+ (let* ((start (point))
+ (color "red")
+ (shr-stylesheet (nconc (list (cons 'color color))
+ shr-stylesheet)))
+ (shr-fontize-dom cont 'shr-strike-through)
+ (shr-colorize-region start (point) color
+ (cdr (assq 'background-color shr-stylesheet)))))
+
(defun shr-parse-style (style)
(when style
(save-match-data
@@ -1391,11 +1454,14 @@ The preference is a float determined from `shr-prefer-media-type'."
(defun shr-tag-img (dom &optional url)
(when (or url
(and dom
- (> (length (dom-attr dom 'src)) 0)))
+ (or (> (length (dom-attr dom 'src)) 0)
+ (> (length (dom-attr dom 'srcset)) 0))))
(when (> (current-column) 0)
(insert "\n"))
(let ((alt (dom-attr dom 'alt))
- (url (shr-expand-url (or url (dom-attr dom 'src)))))
+ (width (shr-string-number (dom-attr dom 'width)))
+ (height (shr-string-number (dom-attr dom 'height)))
+ (url (shr-expand-url (or url (shr--preferred-image dom)))))
(let ((start (point-marker)))
(when (zerop (length alt))
(setq alt "*"))
@@ -1408,7 +1474,8 @@ The preference is a float determined from `shr-prefer-media-type'."
(string-match "\\`data:" url))
(let ((image (shr-image-from-data (substring url (match-end 0)))))
(if image
- (funcall shr-put-image-function image alt)
+ (funcall shr-put-image-function image alt
+ (list :width width :height height))
(insert alt))))
((and (not shr-inhibit-images)
(string-match "\\`cid:" url))
@@ -1417,7 +1484,8 @@ The preference is a float determined from `shr-prefer-media-type'."
(if (or (not shr-content-function)
(not (setq image (funcall shr-content-function url))))
(insert alt)
- (funcall shr-put-image-function image alt))))
+ (funcall shr-put-image-function image alt
+ (list :width width :height height)))))
((or shr-inhibit-images
(and shr-blocked-images
(string-match shr-blocked-images url)))
@@ -1425,20 +1493,26 @@ The preference is a float determined from `shr-prefer-media-type'."
(shr-insert alt))
((and (not shr-ignore-cache)
(url-is-cached (shr-encode-url url)))
- (funcall shr-put-image-function (shr-get-image-data url) alt))
+ (funcall shr-put-image-function (shr-get-image-data url) alt
+ (list :width width :height height)))
(t
- (insert alt " ")
(when (and shr-ignore-cache
(url-is-cached (shr-encode-url url)))
(let ((file (url-cache-create-filename (shr-encode-url url))))
(when (file-exists-p file)
(delete-file file))))
+ (when (image-type-available-p 'svg)
+ (insert-image
+ (shr-make-placeholder-image dom)
+ (or alt "")))
+ (insert " ")
(url-queue-retrieve
(shr-encode-url url) 'shr-image-fetched
- (list (current-buffer) start (set-marker (make-marker) (1- (point))))
+ (list (current-buffer) start (set-marker (make-marker) (point))
+ (list :width width :height height))
t t)))
(when (zerop shr-table-depth) ;; We are not in a table.
- (put-text-property start (point) 'keymap shr-map)
+ (put-text-property start (point) 'keymap shr-image-map)
(put-text-property start (point) 'shr-alt alt)
(put-text-property start (point) 'image-url url)
(put-text-property start (point) 'image-displayer
@@ -1447,6 +1521,89 @@ The preference is a float determined from `shr-prefer-media-type'."
(shr-fill-text
(or (dom-attr dom 'title) alt))))))))
+(defun shr--preferred-image (dom)
+ (let ((srcset (dom-attr dom 'srcset))
+ (frame-width (frame-pixel-width))
+ (width (string-to-number (or (dom-attr dom 'width) "100")))
+ candidate)
+ (when (> (length srcset) 0)
+ ;; srcset consist of a series of URL/size specifications
+ ;; separated by the ", " string.
+ (setq srcset
+ (sort (mapcar
+ (lambda (elem)
+ (let ((spec (split-string elem "[\t\n\r ]+")))
+ (cond
+ ((= (length spec) 1)
+ ;; Make sure it's well formed.
+ (list (car spec) 0))
+ ((string-match "\\([0-9]+\\)x\\'" (cadr spec))
+ ;; If we have an "x" form, then use the width
+ ;; spec to compute the real width.
+ (list (car spec)
+ (* width (string-to-number
+ (match-string 1 (cadr spec))))))
+ (t
+ (list (car spec)
+ (string-to-number (cadr spec)))))))
+ (split-string (replace-regexp-in-string
+ "\\`[\t\n\r ]+\\|[\t\n\r ]+\\'" "" srcset)
+ "[\t\n\r ]*,[\t\n\r ]*"))
+ (lambda (e1 e2)
+ (> (cadr e1) (cadr e2)))))
+ ;; Choose the smallest picture that's bigger than the current
+ ;; frame.
+ (setq candidate (caar srcset))
+ (while (and srcset
+ (> (cadr (car srcset)) frame-width))
+ (setq candidate (caar srcset))
+ (pop srcset)))
+ (or candidate (dom-attr dom 'src))))
+
+(defun shr-string-number (string)
+ (if (null string)
+ nil
+ (setq string (replace-regexp-in-string "[^0-9]" "" string))
+ (if (zerop (length string))
+ nil
+ (string-to-number string))))
+
+(defun shr-make-placeholder-image (dom)
+ (let* ((edges (and
+ (get-buffer-window (current-buffer))
+ (window-inside-pixel-edges
+ (get-buffer-window (current-buffer)))))
+ (scaling (image-compute-scaling-factor image-scaling-factor))
+ (width (truncate
+ (* (or (shr-string-number (dom-attr dom 'width)) 100)
+ scaling)))
+ (height (truncate
+ (* (or (shr-string-number (dom-attr dom 'height)) 100)
+ scaling)))
+ (max-width
+ (and edges
+ (truncate (* shr-max-image-proportion
+ (- (nth 2 edges) (nth 0 edges))))))
+ (max-height (and edges
+ (truncate (* shr-max-image-proportion
+ (- (nth 3 edges) (nth 1 edges))))))
+ svg)
+ (when (and max-width
+ (> width max-width))
+ (setq height (truncate (* (/ (float max-width) width) height))
+ width max-width))
+ (when (and max-height
+ (> height max-height))
+ (setq width (truncate (* (/ (float max-height) height) width))
+ height max-height))
+ (setq svg (svg-create width height))
+ (svg-gradient svg "background" 'linear '((0 . "#b0b0b0") (100 . "#808080")))
+ (svg-rectangle svg 0 0 width height :gradient "background"
+ :stroke-width 2 :stroke-color "black")
+ (let ((image (svg-image svg)))
+ (setf (image-property image :ascent) 100)
+ image)))
+
(defun shr-tag-pre (dom)
(let ((shr-folding-mode 'none)
(shr-current-font 'default))
@@ -1513,7 +1670,9 @@ The preference is a float determined from `shr-prefer-media-type'."
(put-text-property start (1+ start)
'shr-continuation-indentation shr-indentation)
(put-text-property start (1+ start) 'shr-prefix-length (length bullet))
- (shr-generic dom)))))
+ (shr-generic dom))))
+ (unless (bolp)
+ (insert "\n")))
(defun shr-mark-fill (start)
;; We may not have inserted any text to fill.
@@ -1576,6 +1735,24 @@ The preference is a float determined from `shr-prefer-media-type'."
(shr-colorize-region start (point) color
(cdr (assq 'background-color shr-stylesheet))))))
+(defun shr-tag-bdo (dom)
+ (let* ((direction (dom-attr dom 'dir))
+ (char (cond
+ ((equal direction "ltr")
+ ?\N{LEFT-TO-RIGHT OVERRIDE})
+ ((equal direction "rtl")
+ ?\N{RIGHT-TO-LEFT OVERRIDE}))))
+ (when char
+ (insert ?\N{FIRST STRONG ISOLATE} char))
+ (shr-generic dom)
+ (when char
+ (insert ?\N{POP DIRECTIONAL FORMATTING} ?\N{POP DIRECTIONAL ISOLATE}))))
+
+(defun shr-tag-bdi (dom)
+ (insert ?\N{FIRST STRONG ISOLATE})
+ (shr-generic dom)
+ (insert ?\N{POP DIRECTIONAL ISOLATE}))
+
;;; Table rendering algorithm.
;; Table rendering is the only complicated thing here. We do this by
@@ -1721,14 +1898,62 @@ The preference is a float determined from `shr-prefer-media-type'."
bgcolor))
;; Finally, insert all the images after the table. The Emacs buffer
;; model isn't strong enough to allow us to put the images actually
- ;; into the tables.
+ ;; into the tables. It inserts also non-td/th objects.
(when (zerop shr-table-depth)
(save-excursion
(shr-expand-alignments start (point)))
- (dolist (elem (dom-by-tag dom 'object))
- (shr-tag-object elem))
- (dolist (elem (dom-by-tag dom 'img))
- (shr-tag-img elem)))))
+ (let ((strings (shr-collect-extra-strings-in-table dom)))
+ (when strings
+ (save-restriction
+ (narrow-to-region (point) (point))
+ (insert (mapconcat #'identity strings "\n"))
+ (shr-fill-lines (point-min) (point-max))))))))
+
+(defun shr-collect-extra-strings-in-table (dom &optional flags)
+ "Return extra strings in DOM of which the root is a table clause.
+Render <img>s and <object>s, and strings and child <table>s of which
+the parent <td> or <th> is lacking. FLAGS is a cons of two boolean
+flags that control whether to collect or render objects."
+ ;; This function runs recursively and collects strings if the cdr of
+ ;; FLAGS is nil and the car is not nil, and it renders also child
+ ;; <table>s if the cdr is nil. Note: FLAGS may be nil, not a cons.
+ ;; FLAGS becomes (t . nil) if a <tr> clause is found in the children
+ ;; of DOM, and becomes (t . t) if a <td> or a <th> clause is found
+ ;; and the car is t then. When a <table> clause is found, FLAGS
+ ;; becomes nil if the cdr is t then. But if FLAGS is (t . nil) then,
+ ;; it renders the <table>.
+ (cl-loop for child in (dom-children dom) with recurse with tag
+ do (setq recurse nil)
+ if (stringp child)
+ unless (or (not (car flags)) (cdr flags))
+ when (string-match "\\(?:[^\t\n\r ]+[\t\n\r ]+\\)*[^\t\n\r ]+"
+ child)
+ collect (match-string 0 child)
+ end end
+ else if (consp child)
+ do (setq tag (dom-tag child)) and
+ unless (memq tag '(comment style))
+ if (eq tag 'img)
+ do (shr-tag-img child)
+ else if (eq tag 'object)
+ do (shr-tag-object child)
+ else
+ do (setq recurse t) and
+ if (eq tag 'tr)
+ do (setq flags '(t . nil))
+ else if (memq tag '(td th))
+ when (car flags)
+ do (setq flags '(t . t))
+ end
+ else if (eq tag 'table)
+ if (cdr flags)
+ do (setq flags nil)
+ else if (car flags)
+ do (setq recurse nil)
+ (shr-tag-table child)
+ end end end end end end end end end end
+ when recurse
+ append (shr-collect-extra-strings-in-table child flags)))
(defun shr-insert-table (table widths)
(let* ((collapse (equal (cdr (assq 'border-collapse shr-stylesheet))
@@ -1747,7 +1972,7 @@ The preference is a float determined from `shr-prefer-media-type'."
(dolist (column row)
(setq max (max max (nth 2 column))))
max)))
- (dotimes (i (max height 1))
+ (dotimes (_ (max height 1))
(shr-indent)
(insert shr-table-vertical-line "\n"))
(dolist (column row)
@@ -1755,7 +1980,7 @@ The preference is a float determined from `shr-prefer-media-type'."
(goto-char start)
;; Sum up all the widths from the column. (There may be
;; more than one if this is a "colspan" column.)
- (dotimes (i (nth 4 column))
+ (dotimes (_ (nth 4 column))
;; The colspan directive may be wrong and there may not be
;; that number of columns.
(when (<= column-number (1- (length widths)))
@@ -1786,7 +2011,7 @@ The preference is a float determined from `shr-prefer-media-type'."
(forward-line 1))
;; Add blank lines at padding at the bottom of the TD,
;; possibly.
- (dotimes (i (- height (length lines)))
+ (dotimes (_ (- height (length lines)))
(end-of-line)
(let ((start (point)))
(insert (propertize " "
@@ -1968,7 +2193,7 @@ The preference is a float determined from `shr-prefer-media-type'."
(push data tds)))))
(when (and colspan
(> colspan 1))
- (dotimes (c (1- colspan))
+ (dotimes (_ (1- colspan))
(setq i (1+ i))
(push
(if fill
diff --git a/lisp/net/sieve-manage.el b/lisp/net/sieve-manage.el
new file mode 100644
index 00000000000..8f7bd449284
--- /dev/null
+++ b/lisp/net/sieve-manage.el
@@ -0,0 +1,583 @@
+;;; sieve-manage.el --- Implementation of the managesieve protocol in elisp
+
+;; Copyright (C) 2001-2016 Free Software Foundation, Inc.
+
+;; Author: Simon Josefsson <simon@josefsson.org>
+;; Albert Krewinkel <tarleb@moltkeplatz.de>
+
+;; 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 3 of the License, 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. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This library provides an elisp API for the managesieve network
+;; protocol.
+;;
+;; It uses the SASL library for authentication, which means it
+;; supports DIGEST-MD5, CRAM-MD5, SCRAM-MD5, NTLM, PLAIN and LOGIN
+;; methods. STARTTLS is not well tested, but should be easy to get to
+;; work if someone wants.
+;;
+;; The API should be fairly obvious for anyone familiar with the
+;; managesieve protocol, interface functions include:
+;;
+;; `sieve-manage-open'
+;; open connection to managesieve server, returning a buffer to be
+;; used by all other API functions.
+;;
+;; `sieve-manage-opened'
+;; check if a server is open or not
+;;
+;; `sieve-manage-close'
+;; close a server connection.
+;;
+;; `sieve-manage-listscripts'
+;; `sieve-manage-deletescript'
+;; `sieve-manage-getscript'
+;; performs managesieve protocol actions
+;;
+;; and that's it. Example of a managesieve session in *scratch*:
+;;
+;; (with-current-buffer (sieve-manage-open "mail.example.com")
+;; (sieve-manage-authenticate)
+;; (sieve-manage-listscripts))
+;;
+;; => ((active . "main") "vacation")
+;;
+;; References:
+;;
+;; draft-martin-managesieve-02.txt,
+;; "A Protocol for Remotely Managing Sieve Scripts",
+;; by Tim Martin.
+;;
+;; Release history:
+;;
+;; 2001-10-31 Committed to Oort Gnus.
+;; 2002-07-27 Added DELETESCRIPT. Suggested by Ned Ludd.
+;; 2002-08-03 Use SASL library.
+;; 2013-06-05 Enabled STARTTLS support, fixed bit rot.
+
+;;; Code:
+
+(if (locate-library "password-cache")
+ (require 'password-cache)
+ (require 'password))
+
+(eval-when-compile (require 'cl))
+(require 'sasl)
+(require 'starttls)
+(autoload 'sasl-find-mechanism "sasl")
+(autoload 'auth-source-search "auth-source")
+
+;; User customizable variables:
+
+(defgroup sieve-manage nil
+ "Low-level Managesieve protocol issues."
+ :group 'mail
+ :prefix "sieve-")
+
+(defcustom sieve-manage-log "*sieve-manage-log*"
+ "Name of buffer for managesieve session trace."
+ :type 'string
+ :group 'sieve-manage)
+
+(defcustom sieve-manage-server-eol "\r\n"
+ "The EOL string sent from the server."
+ :type 'string
+ :group 'sieve-manage)
+
+(defcustom sieve-manage-client-eol "\r\n"
+ "The EOL string we send to the server."
+ :type 'string
+ :group 'sieve-manage)
+
+(defcustom sieve-manage-authenticators '(digest-md5
+ cram-md5
+ scram-md5
+ ntlm
+ plain
+ login)
+ "Priority of authenticators to consider when authenticating to server."
+ ;; FIXME Improve this. It's not `set'.
+ ;; It's like (repeat (choice (const ...))), where each choice can
+ ;; only appear once.
+ :type '(repeat symbol)
+ :group 'sieve-manage)
+
+(defcustom sieve-manage-authenticator-alist
+ '((cram-md5 sieve-manage-cram-md5-p sieve-manage-cram-md5-auth)
+ (digest-md5 sieve-manage-digest-md5-p sieve-manage-digest-md5-auth)
+ (scram-md5 sieve-manage-scram-md5-p sieve-manage-scram-md5-auth)
+ (ntlm sieve-manage-ntlm-p sieve-manage-ntlm-auth)
+ (plain sieve-manage-plain-p sieve-manage-plain-auth)
+ (login sieve-manage-login-p sieve-manage-login-auth))
+ "Definition of authenticators.
+
+\(NAME CHECK AUTHENTICATE)
+
+NAME names the authenticator. CHECK is a function returning non-nil if
+the server support the authenticator and AUTHENTICATE is a function
+for doing the actual authentication."
+ :type '(repeat (list (symbol :tag "Name") (function :tag "Check function")
+ (function :tag "Authentication function")))
+ :group 'sieve-manage)
+
+(defcustom sieve-manage-default-port "sieve"
+ "Default port number or service name for managesieve protocol."
+ :type '(choice integer string)
+ :version "24.4"
+ :group 'sieve-manage)
+
+(defcustom sieve-manage-default-stream 'network
+ "Default stream type to use for `sieve-manage'."
+ :version "24.1"
+ :type 'symbol
+ :group 'sieve-manage)
+
+(defcustom sieve-manage-ignore-starttls nil
+ "Ignore STARTTLS even if STARTTLS capability is provided."
+ :version "26.1"
+ :type 'boolean
+ :group 'sieve-manage)
+
+;; Internal variables:
+
+(defconst sieve-manage-local-variables '(sieve-manage-server
+ sieve-manage-port
+ sieve-manage-auth
+ sieve-manage-stream
+ sieve-manage-process
+ sieve-manage-client-eol
+ sieve-manage-server-eol
+ sieve-manage-capability))
+(defconst sieve-manage-coding-system-for-read 'binary)
+(defconst sieve-manage-coding-system-for-write 'binary)
+(defvar sieve-manage-stream nil)
+(defvar sieve-manage-auth nil)
+(defvar sieve-manage-server nil)
+(defvar sieve-manage-port nil)
+(defvar sieve-manage-state 'closed
+ "Managesieve state.
+Valid states are `closed', `initial', `nonauth', and `auth'.")
+(defvar sieve-manage-process nil)
+(defvar sieve-manage-capability nil)
+
+;; Internal utility functions
+(autoload 'mm-enable-multibyte "mm-util")
+
+(defun sieve-manage-make-process-buffer ()
+ (with-current-buffer
+ (generate-new-buffer (format " *sieve %s:%s*"
+ sieve-manage-server
+ sieve-manage-port))
+ (mapc 'make-local-variable sieve-manage-local-variables)
+ (mm-enable-multibyte)
+ (buffer-disable-undo)
+ (current-buffer)))
+
+(defun sieve-manage-erase (&optional p buffer)
+ (let ((buffer (or buffer (current-buffer))))
+ (and sieve-manage-log
+ (with-current-buffer (get-buffer-create sieve-manage-log)
+ (mm-enable-multibyte)
+ (buffer-disable-undo)
+ (goto-char (point-max))
+ (insert-buffer-substring buffer (with-current-buffer buffer
+ (point-min))
+ (or p (with-current-buffer buffer
+ (point-max)))))))
+ (delete-region (point-min) (or p (point-max))))
+
+(defun sieve-manage-open-server (server port &optional stream buffer)
+ "Open network connection to SERVER on PORT.
+Return the buffer associated with the connection."
+ (with-current-buffer buffer
+ (sieve-manage-erase)
+ (setq sieve-manage-state 'initial)
+ (destructuring-bind (proc . props)
+ (open-network-stream
+ "SIEVE" buffer server port
+ :type stream
+ :capability-command "CAPABILITY\r\n"
+ :end-of-command "^\\(OK\\|NO\\).*\n"
+ :success "^OK.*\n"
+ :return-list t
+ :starttls-function
+ (lambda (capabilities)
+ (when (and (not sieve-manage-ignore-starttls)
+ (string-match "\\bSTARTTLS\\b" capabilities))
+ "STARTTLS\r\n")))
+ (setq sieve-manage-process proc)
+ (setq sieve-manage-capability
+ (sieve-manage-parse-capability (plist-get props :capabilities)))
+ ;; Ignore new capabilities issues after successful STARTTLS
+ (when (or sieve-manage-ignore-starttls
+ (and (memq stream '(nil network starttls))
+ (eq (plist-get props :type) 'tls)))
+ (sieve-manage-drop-next-answer))
+ (current-buffer))))
+
+;; Authenticators
+(defun sieve-sasl-auth (buffer mech)
+ "Login to server using the SASL MECH method."
+ (message "sieve: Authenticating using %s..." mech)
+ (with-current-buffer buffer
+ (let* ((auth-info (auth-source-search :host sieve-manage-server
+ :port "sieve"
+ :max 1
+ :create t))
+ (user-name (or (plist-get (nth 0 auth-info) :user) ""))
+ (user-password (or (plist-get (nth 0 auth-info) :secret) ""))
+ (user-password (if (functionp user-password)
+ (funcall user-password)
+ user-password))
+ (client (sasl-make-client (sasl-find-mechanism (list mech))
+ user-name "sieve" sieve-manage-server))
+ (sasl-read-passphrase
+ ;; We *need* to copy the password, because sasl will modify it
+ ;; somehow.
+ `(lambda (prompt) ,(copy-sequence user-password)))
+ (step (sasl-next-step client nil))
+ (tag (sieve-manage-send
+ (concat
+ "AUTHENTICATE \""
+ mech
+ "\""
+ (and (sasl-step-data step)
+ (concat
+ " \""
+ (base64-encode-string
+ (sasl-step-data step)
+ 'no-line-break)
+ "\"")))))
+ data rsp)
+ (catch 'done
+ (while t
+ (setq rsp nil)
+ (goto-char (point-min))
+ (while (null (or (progn
+ (setq rsp (sieve-manage-is-string))
+ (if (not (and rsp (looking-at
+ sieve-manage-server-eol)))
+ (setq rsp nil)
+ (goto-char (match-end 0))
+ rsp))
+ (setq rsp (sieve-manage-is-okno))))
+ (accept-process-output sieve-manage-process 1)
+ (goto-char (point-min)))
+ (sieve-manage-erase)
+ (when (sieve-manage-ok-p rsp)
+ (when (and (cadr rsp)
+ (string-match "^SASL \"\\([^\"]+\\)\"" (cadr rsp)))
+ (sasl-step-set-data
+ step (base64-decode-string (match-string 1 (cadr rsp)))))
+ (if (and (setq step (sasl-next-step client step))
+ (setq data (sasl-step-data step)))
+ ;; We got data for server but it's finished
+ (error "Server not ready for SASL data: %s" data)
+ ;; The authentication process is finished.
+ (throw 'done t)))
+ (unless (stringp rsp)
+ (error "Server aborted SASL authentication: %s" (caddr rsp)))
+ (sasl-step-set-data step (base64-decode-string rsp))
+ (setq step (sasl-next-step client step))
+ (sieve-manage-send
+ (if (sasl-step-data step)
+ (concat "\""
+ (base64-encode-string (sasl-step-data step)
+ 'no-line-break)
+ "\"")
+ ""))))
+ (message "sieve: Login using %s...done" mech))))
+
+(defun sieve-manage-cram-md5-p (buffer)
+ (sieve-manage-capability "SASL" "CRAM-MD5" buffer))
+
+(defun sieve-manage-cram-md5-auth (buffer)
+ "Login to managesieve server using the CRAM-MD5 SASL method."
+ (sieve-sasl-auth buffer "CRAM-MD5"))
+
+(defun sieve-manage-digest-md5-p (buffer)
+ (sieve-manage-capability "SASL" "DIGEST-MD5" buffer))
+
+(defun sieve-manage-digest-md5-auth (buffer)
+ "Login to managesieve server using the DIGEST-MD5 SASL method."
+ (sieve-sasl-auth buffer "DIGEST-MD5"))
+
+(defun sieve-manage-scram-md5-p (buffer)
+ (sieve-manage-capability "SASL" "SCRAM-MD5" buffer))
+
+(defun sieve-manage-scram-md5-auth (buffer)
+ "Login to managesieve server using the SCRAM-MD5 SASL method."
+ (sieve-sasl-auth buffer "SCRAM-MD5"))
+
+(defun sieve-manage-ntlm-p (buffer)
+ (sieve-manage-capability "SASL" "NTLM" buffer))
+
+(defun sieve-manage-ntlm-auth (buffer)
+ "Login to managesieve server using the NTLM SASL method."
+ (sieve-sasl-auth buffer "NTLM"))
+
+(defun sieve-manage-plain-p (buffer)
+ (sieve-manage-capability "SASL" "PLAIN" buffer))
+
+(defun sieve-manage-plain-auth (buffer)
+ "Login to managesieve server using the PLAIN SASL method."
+ (sieve-sasl-auth buffer "PLAIN"))
+
+(defun sieve-manage-login-p (buffer)
+ (sieve-manage-capability "SASL" "LOGIN" buffer))
+
+(defun sieve-manage-login-auth (buffer)
+ "Login to managesieve server using the LOGIN SASL method."
+ (sieve-sasl-auth buffer "LOGIN"))
+
+;; Managesieve API
+
+(defun sieve-manage-open (server &optional port stream auth buffer)
+ "Open a network connection to a managesieve SERVER (string).
+Optional argument PORT is port number (integer) on remote server.
+Optional argument STREAM is any of `sieve-manage-streams' (a symbol).
+Optional argument AUTH indicates authenticator to use, see
+`sieve-manage-authenticators' for available authenticators.
+If nil, chooses the best stream the server is capable of.
+Optional argument BUFFER is buffer (buffer, or string naming buffer)
+to work in."
+ (setq sieve-manage-port (or port sieve-manage-default-port))
+ (with-current-buffer (or buffer (sieve-manage-make-process-buffer))
+ (setq sieve-manage-server (or server
+ sieve-manage-server)
+ sieve-manage-stream (or stream
+ sieve-manage-stream
+ sieve-manage-default-stream)
+ sieve-manage-auth (or auth
+ sieve-manage-auth))
+ (message "sieve: Connecting to %s..." sieve-manage-server)
+ (sieve-manage-open-server sieve-manage-server
+ sieve-manage-port
+ sieve-manage-stream
+ (current-buffer))
+ (when (sieve-manage-opened (current-buffer))
+ ;; Choose authenticator
+ (when (and (null sieve-manage-auth)
+ (not (eq sieve-manage-state 'auth)))
+ (dolist (auth sieve-manage-authenticators)
+ (when (funcall (nth 1 (assq auth sieve-manage-authenticator-alist))
+ buffer)
+ (setq sieve-manage-auth auth)
+ (return)))
+ (unless sieve-manage-auth
+ (error "Couldn't figure out authenticator for server")))
+ (sieve-manage-erase)
+ (current-buffer))))
+
+(defun sieve-manage-authenticate (&optional buffer)
+ "Authenticate on server in BUFFER.
+Return `sieve-manage-state' value."
+ (with-current-buffer (or buffer (current-buffer))
+ (if (eq sieve-manage-state 'nonauth)
+ (when (funcall (nth 2 (assq sieve-manage-auth
+ sieve-manage-authenticator-alist))
+ (current-buffer))
+ (setq sieve-manage-state 'auth))
+ sieve-manage-state)))
+
+(defun sieve-manage-opened (&optional buffer)
+ "Return non-nil if connection to managesieve server in BUFFER is open.
+If BUFFER is nil then the current buffer is used."
+ (and (setq buffer (get-buffer (or buffer (current-buffer))))
+ (buffer-live-p buffer)
+ (with-current-buffer buffer
+ (and sieve-manage-process
+ (memq (process-status sieve-manage-process) '(open run))))))
+
+(defun sieve-manage-close (&optional buffer)
+ "Close connection to managesieve server in BUFFER.
+If BUFFER is nil, the current buffer is used."
+ (with-current-buffer (or buffer (current-buffer))
+ (when (sieve-manage-opened)
+ (sieve-manage-send "LOGOUT")
+ (sit-for 1))
+ (when (and sieve-manage-process
+ (memq (process-status sieve-manage-process) '(open run)))
+ (delete-process sieve-manage-process))
+ (setq sieve-manage-process nil)
+ (sieve-manage-erase)
+ t))
+
+(defun sieve-manage-capability (&optional name value buffer)
+ "Check if capability NAME of server BUFFER match VALUE.
+If it does, return the server value of NAME. If not returns nil.
+If VALUE is nil, do not check VALUE and return server value.
+If NAME is nil, return the full server list of capabilities."
+ (with-current-buffer (or buffer (current-buffer))
+ (if (null name)
+ sieve-manage-capability
+ (let ((server-value (cadr (assoc name sieve-manage-capability))))
+ (when (or (null value)
+ (and server-value
+ (string-match value server-value)))
+ server-value)))))
+
+(defun sieve-manage-listscripts (&optional buffer)
+ (with-current-buffer (or buffer (current-buffer))
+ (sieve-manage-send "LISTSCRIPTS")
+ (sieve-manage-parse-listscripts)))
+
+(defun sieve-manage-havespace (name size &optional buffer)
+ (with-current-buffer (or buffer (current-buffer))
+ (sieve-manage-send (format "HAVESPACE \"%s\" %s" name size))
+ (sieve-manage-parse-okno)))
+
+(defun sieve-manage-putscript (name content &optional buffer)
+ (with-current-buffer (or buffer (current-buffer))
+ (sieve-manage-send (format "PUTSCRIPT \"%s\" {%d+}%s%s" name
+ ;; Here we assume that the coding-system will
+ ;; replace each char with a single byte.
+ ;; This is always the case if `content' is
+ ;; a unibyte string.
+ (length content)
+ sieve-manage-client-eol content))
+ (sieve-manage-parse-okno)))
+
+(defun sieve-manage-deletescript (name &optional buffer)
+ (with-current-buffer (or buffer (current-buffer))
+ (sieve-manage-send (format "DELETESCRIPT \"%s\"" name))
+ (sieve-manage-parse-okno)))
+
+(defun sieve-manage-getscript (name output-buffer &optional buffer)
+ (with-current-buffer (or buffer (current-buffer))
+ (sieve-manage-send (format "GETSCRIPT \"%s\"" name))
+ (let ((script (sieve-manage-parse-string)))
+ (sieve-manage-parse-crlf)
+ (with-current-buffer output-buffer
+ (insert script))
+ (sieve-manage-parse-okno))))
+
+(defun sieve-manage-setactive (name &optional buffer)
+ (with-current-buffer (or buffer (current-buffer))
+ (sieve-manage-send (format "SETACTIVE \"%s\"" name))
+ (sieve-manage-parse-okno)))
+
+;; Protocol parsing routines
+
+(defun sieve-manage-wait-for-answer ()
+ (let ((pattern "^\\(OK\\|NO\\).*\n")
+ pos)
+ (while (not pos)
+ (setq pos (search-forward-regexp pattern nil t))
+ (goto-char (point-min))
+ (sleep-for 0 50))
+ pos))
+
+(defun sieve-manage-drop-next-answer ()
+ (sieve-manage-wait-for-answer)
+ (sieve-manage-erase))
+
+(defun sieve-manage-ok-p (rsp)
+ (string= (downcase (or (car-safe rsp) "")) "ok"))
+
+(defun sieve-manage-is-okno ()
+ (when (looking-at (concat
+ "^\\(OK\\|NO\\)\\( (\\([^)]+\\))\\)?\\( \\(.*\\)\\)?"
+ sieve-manage-server-eol))
+ (let ((status (match-string 1))
+ (resp-code (match-string 3))
+ (response (match-string 5)))
+ (when response
+ (goto-char (match-beginning 5))
+ (setq response (sieve-manage-is-string)))
+ (list status resp-code response))))
+
+(defun sieve-manage-parse-okno ()
+ (let (rsp)
+ (while (null rsp)
+ (accept-process-output (get-buffer-process (current-buffer)) 1)
+ (goto-char (point-min))
+ (setq rsp (sieve-manage-is-okno)))
+ (sieve-manage-erase)
+ rsp))
+
+(defun sieve-manage-parse-capability (str)
+ "Parse managesieve capability string `STR'.
+Set variable `sieve-manage-capability' to "
+ (let ((capas (delq nil
+ (mapcar #'split-string-and-unquote
+ (split-string str "\n")))))
+ (when (string= "OK" (caar (last capas)))
+ (setq sieve-manage-state 'nonauth))
+ capas))
+
+(defun sieve-manage-is-string ()
+ (cond ((looking-at "\"\\([^\"]+\\)\"")
+ (prog1
+ (match-string 1)
+ (goto-char (match-end 0))))
+ ((looking-at (concat "{\\([0-9]+\\+?\\)}" sieve-manage-server-eol))
+ (let ((pos (match-end 0))
+ (len (string-to-number (match-string 1))))
+ (if (< (point-max) (+ pos len))
+ nil
+ (goto-char (+ pos len))
+ (buffer-substring pos (+ pos len)))))))
+
+(defun sieve-manage-parse-string ()
+ (let (rsp)
+ (while (null rsp)
+ (accept-process-output (get-buffer-process (current-buffer)) 1)
+ (goto-char (point-min))
+ (setq rsp (sieve-manage-is-string)))
+ (sieve-manage-erase (point))
+ rsp))
+
+(defun sieve-manage-parse-crlf ()
+ (when (looking-at sieve-manage-server-eol)
+ (sieve-manage-erase (match-end 0))))
+
+(defun sieve-manage-parse-listscripts ()
+ (let (tmp rsp data)
+ (while (null rsp)
+ (while (null (or (setq rsp (sieve-manage-is-okno))
+ (setq tmp (sieve-manage-is-string))))
+ (accept-process-output (get-buffer-process (current-buffer)) 1)
+ (goto-char (point-min)))
+ (when tmp
+ (while (not (looking-at (concat "\\( ACTIVE\\)?"
+ sieve-manage-server-eol)))
+ (accept-process-output (get-buffer-process (current-buffer)) 1)
+ (goto-char (point-min)))
+ (if (match-string 1)
+ (push (cons 'active tmp) data)
+ (push tmp data))
+ (goto-char (match-end 0))
+ (setq tmp nil)))
+ (sieve-manage-erase)
+ (if (sieve-manage-ok-p rsp)
+ data
+ rsp)))
+
+(defun sieve-manage-send (cmdstr)
+ (setq cmdstr (concat cmdstr sieve-manage-client-eol))
+ (and sieve-manage-log
+ (with-current-buffer (get-buffer-create sieve-manage-log)
+ (mm-enable-multibyte)
+ (buffer-disable-undo)
+ (goto-char (point-max))
+ (insert cmdstr)))
+ (process-send-string sieve-manage-process cmdstr))
+
+(provide 'sieve-manage)
+
+;; sieve-manage.el ends here
diff --git a/lisp/net/sieve-mode.el b/lisp/net/sieve-mode.el
new file mode 100644
index 00000000000..6aa1b207ee2
--- /dev/null
+++ b/lisp/net/sieve-mode.el
@@ -0,0 +1,212 @@
+;;; sieve-mode.el --- Sieve code editing commands for Emacs
+
+;; Copyright (C) 2001-2016 Free Software Foundation, Inc.
+
+;; Author: Simon Josefsson <simon@josefsson.org>
+
+;; 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 3 of the License, 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. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This file contain editing mode functions and font-lock support for
+;; editing Sieve scripts. It sets up C-mode with support for
+;; sieve-style #-comments and a lightly hacked syntax table. It was
+;; strongly influenced by awk-mode.el.
+;;
+;; Put something similar to the following in your .emacs to use this file:
+;;
+;; (load "~/lisp/sieve")
+;; (setq auto-mode-alist (cons '("\\.siv\\'" . sieve-mode) auto-mode-alist))
+;;
+;; References:
+;;
+;; RFC 3028,
+;; "Sieve: A Mail Filtering Language",
+;; by Tim Showalter.
+;;
+;; Release history:
+;;
+;; 2001-03-02 version 1.0 posted to gnu.emacs.sources
+;; version 1.1 change file extension into ".siv" (official one)
+;; added keymap and menubar to hook into sieve-manage
+;; 2001-10-31 version 1.2 committed to Oort Gnus
+
+;;; Code:
+
+(autoload 'sieve-manage "sieve")
+(autoload 'sieve-upload "sieve")
+(eval-when-compile
+ (require 'font-lock))
+
+(defgroup sieve nil
+ "Sieve."
+ :group 'languages)
+
+(defcustom sieve-mode-hook nil
+ "Hook run in sieve mode buffers."
+ :type 'hook)
+
+;; Font-lock
+
+(defface sieve-control-commands
+ '((((type tty) (class color)) (:foreground "blue" :weight light))
+ (((class grayscale) (background light)) (:foreground "LightGray" :bold t))
+ (((class grayscale) (background dark)) (:foreground "DimGray" :bold t))
+ (((class color) (background light)) (:foreground "Orchid"))
+ (((class color) (background dark)) (:foreground "LightSteelBlue"))
+ (t (:bold t)))
+ "Face used for Sieve Control Commands.")
+
+(defface sieve-action-commands
+ '((((type tty) (class color)) (:foreground "blue" :weight bold))
+ (((class color) (background light)) (:foreground "Blue"))
+ (((class color) (background dark)) (:foreground "LightSkyBlue"))
+ (t (:inverse-video t :bold t)))
+ "Face used for Sieve Action Commands.")
+
+(defface sieve-test-commands
+ '((((type tty) (class color)) (:foreground "magenta"))
+ (((class grayscale) (background light))
+ (:foreground "LightGray" :bold t :underline t))
+ (((class grayscale) (background dark))
+ (:foreground "Gray50" :bold t :underline t))
+ (((class color) (background light)) (:foreground "CadetBlue"))
+ (((class color) (background dark)) (:foreground "Aquamarine"))
+ (t (:bold t :underline t)))
+ "Face used for Sieve Test Commands.")
+
+(defface sieve-tagged-arguments
+ '((((type tty) (class color)) (:foreground "cyan" :weight bold))
+ (((class grayscale) (background light)) (:foreground "LightGray" :bold t))
+ (((class grayscale) (background dark)) (:foreground "DimGray" :bold t))
+ (((class color) (background light)) (:foreground "Purple"))
+ (((class color) (background dark)) (:foreground "Cyan"))
+ (t (:bold t)))
+ "Face used for Sieve Tagged Arguments.")
+
+
+(defconst sieve-font-lock-keywords
+ (eval-when-compile
+ (list
+ ;; control commands
+ (cons (regexp-opt '("require" "if" "else" "elsif" "stop")
+ 'words)
+ 'sieve-control-commands)
+ ;; action commands
+ (cons (regexp-opt '("fileinto" "redirect" "reject" "keep" "discard")
+ 'words)
+ 'sieve-action-commands)
+ ;; test commands
+ (cons (regexp-opt '("address" "allof" "anyof" "exists" "false"
+ "true" "header" "not" "size" "envelope"
+ "body")
+ 'words)
+ 'sieve-test-commands)
+ (cons "\\Sw+:\\sw+"
+ 'sieve-tagged-arguments))))
+
+;; Syntax table
+
+(defvar sieve-mode-syntax-table
+ (let ((st (make-syntax-table)))
+ (modify-syntax-entry ?\\ "\\" st)
+ (modify-syntax-entry ?\n "> " st)
+ (modify-syntax-entry ?\f "> " st)
+ (modify-syntax-entry ?\# "< " st)
+ (modify-syntax-entry ?/ ". 14" st)
+ (modify-syntax-entry ?* ". 23b" st)
+ (modify-syntax-entry ?+ "." st)
+ (modify-syntax-entry ?- "." st)
+ (modify-syntax-entry ?= "." st)
+ (modify-syntax-entry ?% "." st)
+ (modify-syntax-entry ?< "." st)
+ (modify-syntax-entry ?> "." st)
+ (modify-syntax-entry ?& "." st)
+ (modify-syntax-entry ?| "." st)
+ (modify-syntax-entry ?_ "_" st)
+ (modify-syntax-entry ?\' "\"" st)
+ st)
+ "Syntax table in use in sieve-mode buffers.")
+
+
+;; Key map definition
+
+(defvar sieve-mode-map
+ (let ((map (make-sparse-keymap)))
+ (define-key map "\C-c\C-l" 'sieve-upload)
+ (define-key map "\C-c\C-c" 'sieve-upload-and-kill)
+ (define-key map "\C-c\C-m" 'sieve-manage)
+ map)
+ "Key map used in sieve mode.")
+
+;; Menu
+
+(easy-menu-define sieve-mode-menu sieve-mode-map
+ "Sieve Menu."
+ '("Sieve"
+ ["Upload script" sieve-upload t]
+ ["Manage scripts on server" sieve-manage t]))
+
+;; Code for Sieve editing mode.
+
+
+(defun sieve-syntax-propertize (beg end)
+ (goto-char beg)
+ (sieve-syntax-propertize-text end)
+ (funcall
+ (syntax-propertize-rules
+ ;; FIXME: When there's a "text:" with a # comment, the \n plays dual role:
+ ;; it closes the comment and starts the string. This is problematic for us
+ ;; since syntax-table entries can either close a comment or
+ ;; delimit a string, but not both.
+ ("\\_<text:[ \t]*\\(?:#.*\\(.\\)\\)?\\(\n\\)"
+ (1 ">")
+ (2 (prog1 (unless (save-excursion
+ (nth 8 (syntax-ppss (match-beginning 0))))
+ (string-to-syntax "|"))
+ (sieve-syntax-propertize-text end)))))
+ beg end))
+
+(defun sieve-syntax-propertize-text (end)
+ (let ((ppss (syntax-ppss)))
+ (when (and (eq t (nth 3 ppss))
+ (re-search-forward "^\\.\\(\n\\)" end 'move))
+ (put-text-property (match-beginning 1) (match-end 1)
+ 'syntax-table (string-to-syntax "|")))))
+
+;;;###autoload
+(define-derived-mode sieve-mode c-mode "Sieve"
+ "Major mode for editing Sieve code.
+This is much like C mode except for the syntax of comments. Its keymap
+inherits from C mode's and it has the same variables for customizing
+indentation. It has its own abbrev table and its own syntax table.
+
+Turning on Sieve mode runs `sieve-mode-hook'."
+ (set (make-local-variable 'paragraph-start) (concat "$\\|" page-delimiter))
+ (set (make-local-variable 'paragraph-separate) paragraph-start)
+ (set (make-local-variable 'comment-start) "#")
+ (set (make-local-variable 'comment-end) "")
+ ;;(set (make-local-variable 'comment-start-skip) "\\(^\\|\\s-\\);?#+ *")
+ (set (make-local-variable 'comment-start-skip) "#+ *")
+ (set (make-local-variable 'syntax-propertize-function)
+ #'sieve-syntax-propertize)
+ (set (make-local-variable 'font-lock-defaults)
+ '(sieve-font-lock-keywords nil nil ((?_ . "w"))))
+ (easy-menu-add-item nil nil sieve-mode-menu))
+
+(provide 'sieve-mode)
+
+;; sieve-mode.el ends here
diff --git a/lisp/net/sieve.el b/lisp/net/sieve.el
new file mode 100644
index 00000000000..d126d84c5de
--- /dev/null
+++ b/lisp/net/sieve.el
@@ -0,0 +1,373 @@
+;;; sieve.el --- Utilities to manage sieve scripts
+
+;; Copyright (C) 2001-2016 Free Software Foundation, Inc.
+
+;; Author: Simon Josefsson <simon@josefsson.org>
+
+;; 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 3 of the License, 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. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This file contain utilities to facilitate upload, download and
+;; general management of sieve scripts. Currently only the
+;; Managesieve protocol is supported (using sieve-manage.el), but when
+;; (useful) alternatives become available, they might be supported as
+;; well.
+;;
+;; The cursor navigation was inspired by biff-mode by Franklin Lee.
+;;
+;; Release history:
+;;
+;; 2001-10-31 Committed to Oort Gnus.
+;; 2002-07-27 Fix down-mouse-2 and down-mouse-3 in manage-mode. Fix menubar
+;; in manage-mode. Change some messages. Added sieve-deactivate*,
+;; sieve-remove. Fixed help text in manage-mode. Suggested by
+;; Ned Ludd.
+;;
+;; Todo:
+;;
+;; * Namespace? This file contains `sieve-manage' and
+;; `sieve-manage-mode', but there is a sieve-manage.el file as well.
+;; Can't think of a good solution though, this file need a *-mode,
+;; and naming it `sieve-mode' would collide with sieve-mode.el. One
+;; solution would be to come up with some better name that this file
+;; can use that doesn't have the managesieve specific "manage" in
+;; it. sieve-dired? i dunno. we could copy all off sieve.el into
+;; sieve-manage.el too, but I'd like to separate the interface from
+;; the protocol implementation since the backends are likely to
+;; change (well).
+;;
+;; * Define servers? We could have a customize buffer to create a server,
+;; with authentication/stream/etc parameters, much like Gnus, and then
+;; only use names of defined servers when interacting with M-x sieve-*.
+;; Right now you can't use STARTTLS, which sieve-manage.el provides
+
+;;; Code:
+
+(require 'sieve-manage)
+(require 'sieve-mode)
+
+;; User customizable variables:
+
+(defgroup sieve nil
+ "Manage sieve scripts."
+ :version "22.1"
+ :group 'tools)
+
+(defcustom sieve-new-script "<new script>"
+ "Name of name script indicator."
+ :type 'string
+ :group 'sieve)
+
+(defcustom sieve-buffer "*sieve*"
+ "Name of sieve management buffer."
+ :type 'string
+ :group 'sieve)
+
+(defcustom sieve-template "\
+require \"fileinto\";
+
+# Example script (remove comment character '#' to make it effective!):
+#
+# if header :contains \"from\" \"coyote\" {
+# discard;
+# } elsif header :contains [\"subject\"] [\"$$$\"] {
+# discard;
+# } else {
+# fileinto \"INBOX\";
+# }
+"
+ "Template sieve script."
+ :type 'string
+ :group 'sieve)
+
+;; Internal variables:
+
+(defvar sieve-manage-buffer nil)
+(defvar sieve-buffer-header-end nil)
+(defvar sieve-buffer-script-name nil
+ "The real script name of the buffer.")
+(make-local-variable 'sieve-buffer-script-name)
+
+;; Sieve-manage mode:
+
+(defvar sieve-manage-mode-map
+ (let ((map (make-sparse-keymap)))
+ ;; various
+ (define-key map "?" 'sieve-help)
+ (define-key map "h" 'sieve-help)
+ ;; activating
+ (define-key map "m" 'sieve-activate)
+ (define-key map "u" 'sieve-deactivate)
+ (define-key map "\M-\C-?" 'sieve-deactivate-all)
+ ;; navigation keys
+ (define-key map "\C-p" 'sieve-prev-line)
+ (define-key map [up] 'sieve-prev-line)
+ (define-key map "\C-n" 'sieve-next-line)
+ (define-key map [down] 'sieve-next-line)
+ (define-key map " " 'sieve-next-line)
+ (define-key map "n" 'sieve-next-line)
+ (define-key map "p" 'sieve-prev-line)
+ (define-key map "\C-m" 'sieve-edit-script)
+ (define-key map "f" 'sieve-edit-script)
+ (define-key map "o" 'sieve-edit-script-other-window)
+ (define-key map "r" 'sieve-remove)
+ (define-key map "q" 'sieve-bury-buffer)
+ (define-key map "Q" 'sieve-manage-quit)
+ (define-key map [(down-mouse-2)] 'sieve-edit-script)
+ (define-key map [(down-mouse-3)] 'sieve-manage-mode-menu)
+ map)
+ "Keymap for `sieve-manage-mode'.")
+
+(easy-menu-define sieve-manage-mode-menu sieve-manage-mode-map
+ "Sieve Menu."
+ '("Manage Sieve"
+ ["Edit script" sieve-edit-script t]
+ ["Activate script" sieve-activate t]
+ ["Deactivate script" sieve-deactivate t]))
+
+(define-derived-mode sieve-manage-mode fundamental-mode "Sieve-manage"
+ "Mode used for sieve script management."
+ (buffer-disable-undo (current-buffer))
+ (setq truncate-lines t)
+ (easy-menu-add sieve-manage-mode-menu sieve-manage-mode-map))
+
+(put 'sieve-manage-mode 'mode-class 'special)
+
+;; Commands used in sieve-manage mode:
+
+(defun sieve-manage-quit ()
+ "Quit Manage Sieve and close the connection."
+ (interactive)
+ (sieve-manage-close sieve-manage-buffer)
+ (kill-buffer sieve-manage-buffer)
+ (kill-buffer (current-buffer)))
+
+(defun sieve-bury-buffer ()
+ "Bury the Manage Sieve buffer without closing the connection."
+ (interactive)
+ (bury-buffer))
+
+(defun sieve-activate (&optional pos)
+ (interactive "d")
+ (let ((name (sieve-script-at-point)) err)
+ (when (or (null name) (string-equal name sieve-new-script))
+ (error "No sieve script at point"))
+ (message "Activating script %s..." name)
+ (setq err (sieve-manage-setactive name sieve-manage-buffer))
+ (sieve-refresh-scriptlist)
+ (if (sieve-manage-ok-p err)
+ (message "Activating script %s...done" name)
+ (message "Activating script %s...failed: %s" name (nth 2 err)))))
+
+(defun sieve-deactivate-all (&optional pos)
+ (interactive "d")
+ (let ((name (sieve-script-at-point)) err)
+ (message "Deactivating scripts...")
+ (setq err (sieve-manage-setactive "" sieve-manage-buffer))
+ (sieve-refresh-scriptlist)
+ (if (sieve-manage-ok-p err)
+ (message "Deactivating scripts...done")
+ (message "Deactivating scripts...failed: %s" (nth 2 err)))))
+
+(defalias 'sieve-deactivate 'sieve-deactivate-all)
+
+(defun sieve-remove (&optional pos)
+ (interactive "d")
+ (let ((name (sieve-script-at-point)) err)
+ (when (or (null name) (string-equal name sieve-new-script))
+ (error "No sieve script at point"))
+ (message "Removing sieve script %s..." name)
+ (setq err (sieve-manage-deletescript name sieve-manage-buffer))
+ (unless (sieve-manage-ok-p err)
+ (error "Removing sieve script %s...failed: " err))
+ (sieve-refresh-scriptlist)
+ (message "Removing sieve script %s...done" name)))
+
+(defun sieve-edit-script (&optional pos)
+ (interactive "d")
+ (let ((name (sieve-script-at-point)))
+ (unless name
+ (error "No sieve script at point"))
+ (if (not (string-equal name sieve-new-script))
+ (let ((newbuf (generate-new-buffer name))
+ err)
+ (setq err (sieve-manage-getscript name newbuf sieve-manage-buffer))
+ (switch-to-buffer newbuf)
+ (if (sieve-manage-ok-p err)
+ (set-buffer-modified-p nil)
+ (error "Sieve download failed: %s" err)))
+ (switch-to-buffer (get-buffer-create "template.siv"))
+ (insert sieve-template))
+ (sieve-mode)
+ (setq sieve-buffer-script-name name)
+ (goto-char (point-min))
+ (message
+ (substitute-command-keys
+ "Press \\[sieve-upload] to upload script to server."))))
+
+(defmacro sieve-change-region (&rest body)
+ "Turns off sieve-region before executing BODY, then re-enables it after.
+Used to bracket operations which move point in the sieve-buffer."
+ `(progn
+ (sieve-highlight nil)
+ ,@body
+ (sieve-highlight t)))
+(put 'sieve-change-region 'lisp-indent-function 0)
+
+(defun sieve-next-line (&optional arg)
+ (interactive)
+ (unless arg
+ (setq arg 1))
+ (if (save-excursion
+ (forward-line arg)
+ (sieve-script-at-point))
+ (sieve-change-region
+ (forward-line arg))
+ (message "End of list")))
+
+(defun sieve-prev-line (&optional arg)
+ (interactive)
+ (unless arg
+ (setq arg -1))
+ (if (save-excursion
+ (forward-line arg)
+ (sieve-script-at-point))
+ (sieve-change-region
+ (forward-line arg))
+ (message "Beginning of list")))
+
+(defun sieve-help ()
+ "Display help for various sieve commands."
+ (interactive)
+ (if (eq last-command 'sieve-help)
+ ;; would need minor-mode for log-edit-mode
+ (describe-function 'sieve-mode)
+ (message "%s" (substitute-command-keys
+ "`\\[sieve-edit-script]':edit `\\[sieve-activate]':activate `\\[sieve-deactivate]':deactivate `\\[sieve-remove]':remove"))))
+
+;; Create buffer:
+
+(defun sieve-setup-buffer (server port)
+ (setq buffer-read-only nil)
+ (erase-buffer)
+ (buffer-disable-undo)
+ (let* ((port (or port sieve-manage-default-port))
+ (header (format "Server : %s:%s\n\n" server port)))
+ (insert header))
+ (set (make-local-variable 'sieve-buffer-header-end)
+ (point-max)))
+
+(defun sieve-script-at-point (&optional pos)
+ "Return name of sieve script at point POS, or nil."
+ (interactive "d")
+ (get-char-property (or pos (point)) 'script-name))
+
+(defun sieve-highlight (on)
+ "Turn ON or off highlighting on the current language overlay."
+ (overlay-put (car (overlays-at (point))) 'face (if on 'highlight 'default)))
+
+(defun sieve-insert-scripts (scripts)
+ "Format and insert LANGUAGE-LIST strings into current buffer at point."
+ (while scripts
+ (let ((p (point))
+ (ext nil)
+ (script (pop scripts)))
+ (if (consp script)
+ (insert (format " ACTIVE %s" (cdr script)))
+ (insert (format " %s" script)))
+ (setq ext (make-overlay p (point)))
+ (overlay-put ext 'mouse-face 'highlight)
+ (overlay-put ext 'script-name (if (consp script)
+ (cdr script)
+ script))
+ (insert "\n"))))
+
+(defun sieve-open-server (server &optional port)
+ "Open SERVER (on PORT) and authenticate."
+ (with-current-buffer
+ (or ;; open server
+ (set (make-local-variable 'sieve-manage-buffer)
+ (sieve-manage-open server port))
+ (error "Error opening server %s" server))
+ (sieve-manage-authenticate)))
+
+(defun sieve-refresh-scriptlist ()
+ (interactive)
+ (with-current-buffer sieve-buffer
+ (setq buffer-read-only nil)
+ (delete-region (or sieve-buffer-header-end (point-max)) (point-max))
+ (goto-char (point-max))
+ ;; get list of script names and print them
+ (let ((scripts (sieve-manage-listscripts sieve-manage-buffer)))
+ (if (null scripts)
+ (insert
+ (substitute-command-keys
+ (format
+ "No scripts on server, press \\[sieve-edit-script] on %s to create a new script.\n"
+ sieve-new-script)))
+ (insert
+ (substitute-command-keys
+ (format (concat "%d script%s on server, press \\[sieve-edit-script] on a script "
+ "name edits it, or\npress \\[sieve-edit-script] on %s to create "
+ "a new script.\n") (length scripts)
+ (if (eq (length scripts) 1) "" "s")
+ sieve-new-script))))
+ (save-excursion
+ (sieve-insert-scripts (list sieve-new-script))
+ (sieve-insert-scripts scripts)))
+ (sieve-highlight t)
+ (setq buffer-read-only t)))
+
+;;;###autoload
+(defun sieve-manage (server &optional port)
+ (interactive "sServer: ")
+ (switch-to-buffer (get-buffer-create sieve-buffer))
+ (sieve-manage-mode)
+ (sieve-setup-buffer server port)
+ (if (sieve-open-server server port)
+ (sieve-refresh-scriptlist)
+ (message "Could not open server %s" server)))
+
+;;;###autoload
+(defun sieve-upload (&optional name)
+ (interactive)
+ (when (or (get-buffer sieve-buffer) (call-interactively 'sieve-manage))
+ (let ((script (buffer-string)) err)
+ (with-current-buffer (get-buffer sieve-buffer)
+ (setq err (sieve-manage-putscript
+ (or name sieve-buffer-script-name (buffer-name))
+ script sieve-manage-buffer))
+ (if (sieve-manage-ok-p err)
+ (message (substitute-command-keys
+ "Sieve upload done. Use \\[sieve-manage] to manage scripts."))
+ (message "Sieve upload failed: %s" (nth 2 err)))))))
+
+;;;###autoload
+(defun sieve-upload-and-bury (&optional name)
+ (interactive)
+ (sieve-upload name)
+ (bury-buffer))
+
+;;;###autoload
+(defun sieve-upload-and-kill (&optional name)
+ (interactive)
+ (sieve-upload name)
+ (kill-buffer))
+
+(provide 'sieve)
+
+;; sieve.el ends here
diff --git a/lisp/net/soap-client.el b/lisp/net/soap-client.el
index 12c9f419555..f8973a3a537 100644
--- a/lisp/net/soap-client.el
+++ b/lisp/net/soap-client.el
@@ -5,7 +5,7 @@
;; Author: Alexandru Harsanyi <AlexHarsanyi@gmail.com>
;; Author: Thomas Fitzsimmons <fitzsim@fitzsim.org>
;; Created: December, 2009
-;; Version: 3.0.2
+;; Version: 3.1.1
;; Keywords: soap, web-services, comm, hypermedia
;; Package: soap-client
;; Homepage: https://github.com/alex-hhh/emacs-soap-client
@@ -1249,8 +1249,8 @@ See also `soap-wsdl-resolve-references'."
(when messages
(error (mapconcat 'identity (nreverse messages) "; and: "))))
(cl-labels ((fail-with-message (format value)
- (push (format format value) messages)
- (throw 'invalid nil)))
+ (push (format format value) messages)
+ (throw 'invalid nil)))
(catch 'invalid
(let ((enumeration (soap-xs-simple-type-enumeration type)))
(when (and (> (length enumeration) 1)
@@ -1630,7 +1630,7 @@ This is a specialization of `soap-encode-value' for
`soap-xs-complex-type' objects."
(case (soap-xs-complex-type-indicator type)
(array
- (error "soap-encode-xs-complex-type arrays are handled elsewhere"))
+ (error "Arrays of type soap-encode-xs-complex-type are handled elsewhere"))
((sequence choice all nil)
(let ((type-list (list type)))
@@ -2999,6 +2999,33 @@ http://schemas.xmlsoap.org/soap/encoding/\"\n"))
:type 'boolean
:group 'soap-client)
+(defun soap-find-port (wsdl service)
+ "Return the WSDL port having SERVICE name.
+Signal an error if not found."
+ (or (catch 'found
+ (dolist (p (soap-wsdl-ports wsdl))
+ (when (equal service (soap-element-name p))
+ (throw 'found p))))
+ (error "Unknown SOAP service: %s" service)))
+
+(defun soap-find-operation (port operation-name)
+ "Inside PORT, find OPERATION-NAME, a `soap-port-type'.
+Signal an error if not found."
+ (let* ((binding (soap-port-binding port))
+ (op (gethash operation-name (soap-binding-operations binding))))
+ (or op
+ (error "No operation %s for SOAP service %s"
+ operation-name (soap-element-name port)))))
+
+(defun soap-operation-arity (wsdl service operation-name)
+ "Return the number of arguments required by a soap operation.
+WSDL, SERVICE, OPERATION-NAME and PARAMETERS are as described in
+`soap-invoke'."
+ (let* ((port (soap-find-port wsdl service))
+ (op (soap-find-operation port operation-name))
+ (bop (soap-bound-operation-operation op)))
+ (length (soap-operation-parameter-order bop))))
+
(defun soap-invoke-internal (callback cbargs wsdl service operation-name
&rest parameters)
"Implement `soap-invoke' and `soap-invoke-async'.
@@ -3006,54 +3033,43 @@ If CALLBACK is non-nil, operate asynchronously, then call CALLBACK as (apply
CALLBACK RESPONSE CBARGS), where RESPONSE is the SOAP invocation result.
If CALLBACK is nil, operate synchronously. WSDL, SERVICE,
OPERATION-NAME and PARAMETERS are as described in `soap-invoke'."
- (let ((port (catch 'found
- (dolist (p (soap-wsdl-ports wsdl))
- (when (equal service (soap-element-name p))
- (throw 'found p))))))
- (unless port
- (error "Unknown SOAP service: %s" service))
-
- (let* ((binding (soap-port-binding port))
- (operation (gethash operation-name
- (soap-binding-operations binding))))
- (unless operation
- (error "No operation %s for SOAP service %s" operation-name service))
-
- (let ((url-request-method "POST")
- (url-package-name "soap-client.el")
- (url-package-version "1.0")
- (url-request-data
- ;; url-request-data expects a unibyte string already encoded...
- (encode-coding-string
- (soap-create-envelope operation parameters wsdl
- (soap-port-service-url port))
- 'utf-8))
- (url-mime-charset-string "utf-8;q=1, iso-8859-1;q=0.5")
- (url-http-attempt-keepalives t)
- (url-request-extra-headers
- (list
- (cons "SOAPAction"
- (concat "\"" (soap-bound-operation-soap-action
- operation) "\""))
- (cons "Content-Type"
- "text/xml; charset=utf-8"))))
- (if callback
- (url-retrieve
- (soap-port-service-url port)
- (lambda (status)
- (let ((data-buffer (current-buffer)))
- (unwind-protect
- (let ((error-status (plist-get status :error)))
- (if error-status
- (signal (car error-status) (cdr error-status))
- (apply callback
- (soap-parse-envelope
- (soap-parse-server-response)
- operation wsdl)
- cbargs)))
- ;; Ensure the url-retrieve buffer is not leaked.
- (and (buffer-live-p data-buffer)
- (kill-buffer data-buffer))))))
+ (let* ((port (soap-find-port wsdl service))
+ (operation (soap-find-operation port operation-name)))
+ (let ((url-request-method "POST")
+ (url-package-name "soap-client.el")
+ (url-package-version "1.0")
+ (url-request-data
+ ;; url-request-data expects a unibyte string already encoded...
+ (encode-coding-string
+ (soap-create-envelope operation parameters wsdl
+ (soap-port-service-url port))
+ 'utf-8))
+ (url-mime-charset-string "utf-8;q=1, iso-8859-1;q=0.5")
+ (url-http-attempt-keepalives t)
+ (url-request-extra-headers
+ (list
+ (cons "SOAPAction"
+ (concat "\"" (soap-bound-operation-soap-action
+ operation) "\""))
+ (cons "Content-Type"
+ "text/xml; charset=utf-8"))))
+ (if callback
+ (url-retrieve
+ (soap-port-service-url port)
+ (lambda (status)
+ (let ((data-buffer (current-buffer)))
+ (unwind-protect
+ (let ((error-status (plist-get status :error)))
+ (if error-status
+ (signal (car error-status) (cdr error-status))
+ (apply callback
+ (soap-parse-envelope
+ (soap-parse-server-response)
+ operation wsdl)
+ cbargs)))
+ ;; Ensure the url-retrieve buffer is not leaked.
+ (and (buffer-live-p data-buffer)
+ (kill-buffer data-buffer))))))
(let ((buffer (url-retrieve-synchronously
(soap-port-service-url port))))
(condition-case err
@@ -3077,7 +3093,7 @@ OPERATION-NAME and PARAMETERS are as described in `soap-invoke'."
(error
(when soap-debug
(pop-to-buffer buffer))
- (error (error-message-string err))))))))))
+ (error (error-message-string err)))))))))
(defun soap-invoke (wsdl service operation-name &rest parameters)
"Invoke a SOAP operation and return the result.
diff --git a/lisp/net/starttls.el b/lisp/net/starttls.el
new file mode 100644
index 00000000000..b9255901f97
--- /dev/null
+++ b/lisp/net/starttls.el
@@ -0,0 +1,304 @@
+;;; starttls.el --- STARTTLS functions
+
+;; Copyright (C) 1999-2016 Free Software Foundation, Inc.
+
+;; Author: Daiki Ueno <ueno@unixuser.org>
+;; Author: Simon Josefsson <simon@josefsson.org>
+;; Created: 1999/11/20
+;; Keywords: TLS, SSL, OpenSSL, GnuTLS, mail, news
+
+;; 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 3 of the License, 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. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This module defines some utility functions for STARTTLS profiles.
+
+;; [RFC 2595] "Using TLS with IMAP, POP3 and ACAP"
+;; by Chris Newman <chris.newman@innosoft.com> (1999/06)
+
+;; This file now contains a combination of the two previous
+;; implementations both called "starttls.el". The first one is Daiki
+;; Ueno's starttls.el which uses his own "starttls" command line tool,
+;; and the second one is Simon Josefsson's starttls.el which uses
+;; "gnutls-cli" from GnuTLS.
+;;
+;; If "starttls" is available, it is preferred by the code over
+;; "gnutls-cli", for backwards compatibility. Use
+;; `starttls-use-gnutls' to toggle between implementations if you have
+;; both tools installed. It is recommended to use GnuTLS, though, as
+;; it performs more verification of the certificates.
+
+;; The GnuTLS support requires GnuTLS 0.9.90 (released 2003-10-08) or
+;; later, from <http://www.gnu.org/software/gnutls/>, or "starttls"
+;; from <ftp://ftp.opaopa.org/pub/elisp/>.
+
+;; Usage is similar to `open-network-stream'. For example:
+;;
+;; (when (setq tmp (starttls-open-stream
+;; "test" (current-buffer) "yxa.extundo.com" 25))
+;; (accept-process-output tmp 15)
+;; (process-send-string tmp "STARTTLS\n")
+;; (accept-process-output tmp 15)
+;; (message "STARTTLS output:\n%s" (starttls-negotiate tmp))
+;; (process-send-string tmp "EHLO foo\n"))
+
+;; An example run yields the following output:
+;;
+;; 220 yxa.extundo.com ESMTP Sendmail 8.12.11/8.12.11/Debian-3; Wed, 26 May 2004 19:12:29 +0200; (No UCE/UBE) logging access from: c494102a.s-bi.bostream.se(OK)-c494102a.s-bi.bostream.se [217.215.27.65]
+;; 220 2.0.0 Ready to start TLS
+;; 250-yxa.extundo.com Hello c494102a.s-bi.bostream.se [217.215.27.65], pleased to meet you
+;; 250-ENHANCEDSTATUSCODES
+;; 250-PIPELINING
+;; 250-EXPN
+;; 250-VERB
+;; 250-8BITMIME
+;; 250-SIZE
+;; 250-DSN
+;; 250-ETRN
+;; 250-AUTH DIGEST-MD5 CRAM-MD5 PLAIN LOGIN
+;; 250-DELIVERBY
+;; 250 HELP
+;; nil
+;;
+;; With the message buffer containing:
+;;
+;; STARTTLS output:
+;; *** Starting TLS handshake
+;; - Server's trusted authorities:
+;; [0]: C=SE,ST=Stockholm,L=Stockholm,O=YXA,OU=CA,CN=yxa.extundo.com,EMAIL=staff@yxa.extundo.com
+;; - Certificate type: X.509
+;; - Got a certificate list of 2 certificates.
+;;
+;; - Certificate[0] info:
+;; # The hostname in the certificate matches 'yxa.extundo.com'.
+;; # valid since: Wed May 26 12:16:00 CEST 2004
+;; # expires at: Wed Jul 26 12:16:00 CEST 2023
+;; # serial number: 04
+;; # fingerprint: 7c 04 4b c1 fa 26 9b 5d 90 22 52 3c 65 3d 85 3a
+;; # version: #1
+;; # public key algorithm: RSA
+;; # Modulus: 1024 bits
+;; # Subject's DN: C=SE,ST=Stockholm,L=Stockholm,O=YXA,OU=Mail server,CN=yxa.extundo.com,EMAIL=staff@yxa.extundo.com
+;; # Issuer's DN: C=SE,ST=Stockholm,L=Stockholm,O=YXA,OU=CA,CN=yxa.extundo.com,EMAIL=staff@yxa.extundo.com
+;;
+;; - Certificate[1] info:
+;; # valid since: Sun May 23 11:35:00 CEST 2004
+;; # expires at: Sun Jul 23 11:35:00 CEST 2023
+;; # serial number: 00
+;; # fingerprint: fc 76 d8 63 1a c9 0b 3b fa 40 fe ed 47 7a 58 ae
+;; # version: #3
+;; # public key algorithm: RSA
+;; # Modulus: 1024 bits
+;; # Subject's DN: C=SE,ST=Stockholm,L=Stockholm,O=YXA,OU=CA,CN=yxa.extundo.com,EMAIL=staff@yxa.extundo.com
+;; # Issuer's DN: C=SE,ST=Stockholm,L=Stockholm,O=YXA,OU=CA,CN=yxa.extundo.com,EMAIL=staff@yxa.extundo.com
+;;
+;; - Peer's certificate issuer is unknown
+;; - Peer's certificate is NOT trusted
+;; - Version: TLS 1.0
+;; - Key Exchange: RSA
+;; - Cipher: ARCFOUR 128
+;; - MAC: SHA
+;; - Compression: NULL
+
+;;; Code:
+
+(defgroup starttls nil
+ "Support for `Transport Layer Security' protocol."
+ :version "21.1"
+ :group 'mail)
+
+(defcustom starttls-gnutls-program "gnutls-cli"
+ "Name of GnuTLS command line tool.
+This program is used when GnuTLS is used, i.e. when
+`starttls-use-gnutls' is non-nil."
+ :version "22.1"
+ :type 'string
+ :group 'starttls)
+
+(defcustom starttls-program "starttls"
+ "The program to run in a subprocess to open an TLSv1 connection.
+This program is used when the `starttls' command is used,
+i.e. when `starttls-use-gnutls' is nil."
+ :type 'string
+ :group 'starttls)
+
+(defcustom starttls-use-gnutls (not (executable-find starttls-program))
+ "Whether to use GnuTLS instead of the `starttls' command."
+ :version "22.1"
+ :type 'boolean
+ :group 'starttls)
+
+(defcustom starttls-extra-args nil
+ "Extra arguments to `starttls-program'.
+These apply when the `starttls' command is used, i.e. when
+`starttls-use-gnutls' is nil."
+ :type '(repeat string)
+ :group 'starttls)
+
+(defcustom starttls-extra-arguments nil
+ "Extra arguments to `starttls-gnutls-program'.
+These apply when GnuTLS is used, i.e. when `starttls-use-gnutls' is non-nil.
+
+For example, non-TLS compliant servers may require
+\(\"--protocols\" \"ssl3\"). Invoke \"gnutls-cli --help\" to
+find out which parameters are available."
+ :version "22.1"
+ :type '(repeat string)
+ :group 'starttls)
+
+(defcustom starttls-process-connection-type nil
+ "Value for `process-connection-type' to use when starting STARTTLS process."
+ :version "22.1"
+ :type 'boolean
+ :group 'starttls)
+
+(defcustom starttls-connect "- Simple Client Mode:\n\n"
+ "Regular expression indicating successful connection.
+The default is what GnuTLS's \"gnutls-cli\" outputs."
+ ;; GnuTLS cli.c:main() prints this string when it is starting to run
+ ;; in the application read/write phase. If the logic, or the string
+ ;; itself, is modified, this must be updated.
+ :version "22.1"
+ :type 'regexp
+ :group 'starttls)
+
+(defcustom starttls-failure "\\*\\*\\* Handshake has failed"
+ "Regular expression indicating failed TLS handshake.
+The default is what GnuTLS's \"gnutls-cli\" outputs."
+ ;; GnuTLS cli.c:do_handshake() prints this string on failure. If the
+ ;; logic, or the string itself, is modified, this must be updated.
+ :version "22.1"
+ :type 'regexp
+ :group 'starttls)
+
+(defcustom starttls-success "- Compression: "
+ "Regular expression indicating completed TLS handshakes.
+The default is what GnuTLS's \"gnutls-cli\" outputs."
+ ;; GnuTLS cli.c:do_handshake() calls, on success,
+ ;; common.c:print_info(), that unconditionally print this string
+ ;; last. If that logic, or the string itself, is modified, this
+ ;; must be updated.
+ :version "22.1"
+ :type 'regexp
+ :group 'starttls)
+
+(defun starttls-negotiate-gnutls (process)
+ "Negotiate TLS on PROCESS opened by `open-starttls-stream'.
+This should typically only be done once. It typically returns a
+multi-line informational message with information about the
+handshake, or nil on failure."
+ (let (buffer info old-max done-ok done-bad)
+ (if (null (setq buffer (process-buffer process)))
+ ;; XXX How to remove/extract the TLS negotiation junk?
+ (signal-process (process-id process) 'SIGALRM)
+ (with-current-buffer buffer
+ (save-excursion
+ (setq old-max (goto-char (point-max)))
+ (signal-process (process-id process) 'SIGALRM)
+ (while (and (processp process)
+ (eq (process-status process) 'run)
+ (save-excursion
+ (goto-char old-max)
+ (not (or (setq done-ok (re-search-forward
+ starttls-success nil t))
+ (setq done-bad (re-search-forward
+ starttls-failure nil t))))))
+ (accept-process-output process 1 100)
+ (sit-for 0.1))
+ (setq info (buffer-substring-no-properties old-max (point-max)))
+ (delete-region old-max (point-max))
+ (if (or (and done-ok (not done-bad))
+ ;; Prevent mitm that fake success msg after failure msg.
+ (and done-ok done-bad (< done-ok done-bad)))
+ info
+ (message "STARTTLS negotiation failed: %s" info)
+ nil))))))
+
+(defun starttls-negotiate (process)
+ (if starttls-use-gnutls
+ (starttls-negotiate-gnutls process)
+ (signal-process (process-id process) 'SIGALRM)))
+
+(defun starttls-open-stream-gnutls (name buffer host port)
+ (message "Opening STARTTLS connection to `%s:%s'..." host port)
+ (let* (done
+ (old-max (with-current-buffer buffer (point-max)))
+ (process-connection-type starttls-process-connection-type)
+ (process (apply #'start-process name buffer
+ starttls-gnutls-program "-s" host
+ "-p" (if (integerp port)
+ (int-to-string port)
+ port)
+ starttls-extra-arguments)))
+ (set-process-query-on-exit-flag process nil)
+ (while (and (processp process)
+ (eq (process-status process) 'run)
+ (with-current-buffer buffer
+ (goto-char old-max)
+ (not (setq done (re-search-forward
+ starttls-connect nil t)))))
+ (accept-process-output process 0 100)
+ (sit-for 0.1))
+ (if done
+ (with-current-buffer buffer
+ (delete-region old-max done))
+ (delete-process process)
+ (setq process nil))
+ (message "Opening STARTTLS connection to `%s:%s'...%s"
+ host port (if done "done" "failed"))
+ process))
+
+;;;###autoload
+(defun starttls-open-stream (name buffer host port)
+ "Open a TLS connection for a port to a host.
+Returns a subprocess object to represent the connection.
+Input and output work as for subprocesses; `delete-process' closes it.
+Args are NAME BUFFER HOST PORT.
+NAME is name for process. It is modified if necessary to make it unique.
+BUFFER is the buffer (or `buffer-name') to associate with the process.
+ Process output goes at end of that buffer, unless you specify
+ an output stream or filter function to handle the output.
+ BUFFER may be also nil, meaning that this process is not associated
+ with any buffer
+Third arg is name of the host to connect to, or its IP address.
+Fourth arg PORT is an integer specifying a port to connect to.
+If `starttls-use-gnutls' is nil, this may also be a service name, but
+GnuTLS requires a port number."
+ (if starttls-use-gnutls
+ (starttls-open-stream-gnutls name buffer host port)
+ (message "Opening STARTTLS connection to `%s:%s'" host (format "%s" port))
+ (let* ((process-connection-type starttls-process-connection-type)
+ (process (apply #'start-process
+ name buffer starttls-program
+ host (format "%s" port)
+ starttls-extra-args)))
+ (set-process-query-on-exit-flag process nil)
+ process)))
+
+(defun starttls-available-p ()
+ "Say whether the STARTTLS programs are available."
+ (and (not (memq system-type '(windows-nt ms-dos)))
+ (executable-find (if starttls-use-gnutls
+ starttls-gnutls-program
+ starttls-program))))
+
+(defalias 'starttls-any-program-available 'starttls-available-p)
+(make-obsolete 'starttls-any-program-available 'starttls-available-p
+ "2011-08-02")
+
+(provide 'starttls)
+
+;;; starttls.el ends here
diff --git a/lisp/net/tramp-adb.el b/lisp/net/tramp-adb.el
index 32fd1888d36..a4218c28ab3 100644
--- a/lisp/net/tramp-adb.el
+++ b/lisp/net/tramp-adb.el
@@ -35,16 +35,13 @@
(require 'tramp)
-;; Pacify byte-compiler.
-(defvar directory-listing-before-filename-regexp)
-(defvar directory-sep-char)
-
;;;###tramp-autoload
(defcustom tramp-adb-program "adb"
"Name of the Android Debug Bridge program."
:group 'tramp
:version "24.4"
- :type 'string)
+ :type 'string
+ :require 'tramp)
;;;###tramp-autoload
(defcustom tramp-adb-connect-if-not-connected nil
@@ -52,11 +49,12 @@
It is used for TCP/IP devices."
:group 'tramp
:version "25.1"
- :type 'boolean)
+ :type 'boolean
+ :require 'tramp)
;;;###tramp-autoload
(defconst tramp-adb-method "adb"
- "*When this method name is used, forward all calls to Android Debug Bridge.")
+ "When this method name is used, forward all calls to Android Debug Bridge.")
;;;###tramp-autoload
(defcustom tramp-adb-prompt
@@ -64,10 +62,12 @@ It is used for TCP/IP devices."
"Regexp used as prompt in almquist shell."
:type 'string
:version "24.4"
- :group 'tramp)
+ :group 'tramp
+ :require 'tramp)
(defconst tramp-adb-ls-date-regexp
- "[[:space:]][0-9]\\{4\\}-[0-9][0-9]-[0-9][0-9][[:space:]][0-9][0-9]:[0-9][0-9][[:space:]]")
+ "[[:space:]][0-9]\\{4\\}-[0-9][0-9]-[0-9][0-9][[:space:]][0-9][0-9]:[0-9][0-9][[:space:]]"
+ "Regexp for date format in ls output.")
(defconst tramp-adb-ls-toolbox-regexp
(concat
@@ -76,7 +76,8 @@ It is used for TCP/IP devices."
"[[:space:]]+\\([^[:space:]]+\\)" ; \3 group
"[[:space:]]+\\([[:digit:]]+\\)" ; \4 size
"[[:space:]]+\\([-[:digit:]]+[[:space:]][:[:digit:]]+\\)" ; \5 date
- "[[:space:]]\\(.*\\)$")) ; \6 filename
+ "[[:space:]]\\(.*\\)$") ; \6 filename
+ "Regexp for ls output.")
;;;###tramp-autoload
(add-to-list 'tramp-methods
@@ -109,7 +110,6 @@ It is used for TCP/IP devices."
(directory-files . tramp-handle-directory-files)
(directory-files-and-attributes
. tramp-adb-handle-directory-files-and-attributes)
- (dired-call-process . ignore)
(dired-compress-file . ignore)
(dired-uncache . tramp-handle-dired-uncache)
(expand-file-name . tramp-adb-handle-expand-file-name)
@@ -126,6 +126,7 @@ It is used for TCP/IP devices."
(file-modes . tramp-handle-file-modes)
(file-name-all-completions . tramp-adb-handle-file-name-all-completions)
(file-name-as-directory . tramp-handle-file-name-as-directory)
+ (file-name-case-insensitive-p . tramp-handle-file-name-case-insensitive-p)
(file-name-completion . tramp-handle-file-name-completion)
(file-name-directory . tramp-handle-file-name-directory)
(file-name-nondirectory . tramp-handle-file-name-nondirectory)
@@ -151,6 +152,7 @@ It is used for TCP/IP devices."
(make-auto-save-file-name . tramp-handle-make-auto-save-file-name)
(make-directory . tramp-adb-handle-make-directory)
(make-directory-internal . ignore)
+ (make-nearby-temp-file . tramp-handle-make-nearby-temp-file)
(make-symbolic-link . tramp-handle-make-symbolic-link)
(process-file . tramp-adb-handle-process-file)
(rename-file . tramp-adb-handle-rename-file)
@@ -162,7 +164,8 @@ It is used for TCP/IP devices."
(shell-command . tramp-adb-handle-shell-command)
(start-file-process . tramp-adb-handle-start-file-process)
(substitute-in-file-name . tramp-handle-substitute-in-file-name)
- (unhandled-file-name-directory . tramp-handle-unhandled-file-name-directory)
+ (temporary-file-directory . tramp-handle-temporary-file-directory)
+ (unhandled-file-name-directory . ignore)
(vc-registered . ignore)
(verify-visited-file-modtime . tramp-handle-verify-visited-file-modtime)
(write-region . tramp-adb-handle-write-region))
@@ -199,8 +202,8 @@ pass to the OPERATION."
tramp-current-host nil nil))
result)
(tramp-message v 6 "%s" (mapconcat 'identity (process-command p) " "))
- (tramp-compat-set-process-query-on-exit-flag p nil)
- (while (eq 'run (process-status p))
+ (set-process-query-on-exit-flag p nil)
+ (while (tramp-compat-process-live-p p)
(accept-process-output p 0.1))
(accept-process-output p 0.1)
(tramp-message v 6 "\n%s" (buffer-string))
@@ -213,7 +216,7 @@ pass to the OPERATION."
(lambda (elt)
(setcar
(cdr elt)
- (tramp-compat-replace-regexp-in-string
+ (replace-regexp-in-string
":" tramp-prefix-port-format (car (cdr elt)))))
result)
result))))
@@ -233,12 +236,9 @@ pass to the OPERATION."
(unless (tramp-run-real-handler 'file-name-absolute-p (list localname))
(setq localname (concat "/" localname)))
;; Do normal `expand-file-name' (this does "/./" and "/../").
- ;; We bind `directory-sep-char' here for XEmacs on Windows,
- ;; which would otherwise use backslash. `default-directory' is
- ;; bound, because on Windows there would be problems with UNC
- ;; shares or Cygwin mounts.
- (let ((directory-sep-char ?/)
- (default-directory (tramp-compat-temporary-file-directory)))
+ ;; `default-directory' is bound, because on Windows there would
+ ;; be problems with UNC shares or Cygwin mounts.
+ (let ((default-directory (tramp-compat-temporary-file-directory)))
(tramp-make-tramp-file-name
method user host
(tramp-drop-volume-letter
@@ -247,7 +247,9 @@ pass to the OPERATION."
(defun tramp-adb-handle-file-directory-p (filename)
"Like `file-directory-p' for Tramp files."
- (car (file-attributes (file-truename filename))))
+ (eq (tramp-compat-file-attribute-type
+ (file-attributes (file-truename filename)))
+ t))
;; This is derived from `tramp-sh-handle-file-truename'. Maybe the
;; code could be shared?
@@ -261,8 +263,7 @@ pass to the OPERATION."
(with-tramp-file-property v localname "file-truename"
(let ((result nil)) ; result steps in reverse order
(tramp-message v 4 "Finding true name for `%s'" filename)
- (let* ((directory-sep-char ?/)
- (steps (tramp-compat-split-string localname "/"))
+ (let* ((steps (split-string localname "/" 'omit))
(localnamedir (tramp-run-real-handler
'file-name-as-directory (list localname)))
(is-dir (string= localname localnamedir))
@@ -283,14 +284,15 @@ pass to the OPERATION."
(append '("") (reverse result) (list thisstep))
"/"))
(setq symlink-target
- (nth 0 (file-attributes
- (tramp-make-tramp-file-name
- method user host
- (mapconcat 'identity
- (append '("")
- (reverse result)
- (list thisstep))
- "/")))))
+ (tramp-compat-file-attribute-type
+ (file-attributes
+ (tramp-make-tramp-file-name
+ method user host
+ (mapconcat 'identity
+ (append '("")
+ (reverse result)
+ (list thisstep))
+ "/")))))
(cond ((string= "." thisstep)
(tramp-message v 5 "Ignoring step `.'"))
((string= ".." thisstep)
@@ -312,8 +314,7 @@ pass to the OPERATION."
"Symlink target `%s' on wrong host" symlink-target))
(setq symlink-target localname))
(setq steps
- (append (tramp-compat-split-string
- symlink-target "/")
+ (append (split-string symlink-target "/" 'omit)
steps)))
(t
;; It's a file.
@@ -434,6 +435,7 @@ pass to the OPERATION."
result)))))))))
(defun tramp-adb-get-ls-command (vec)
+ "Determine `ls' command at its arguments."
(with-tramp-connection-property vec "ls"
(tramp-message vec 5 "Finding a suitable `ls' command")
(if (tramp-adb-send-command-and-check vec "ls --color=never -al /dev/null")
@@ -443,16 +445,14 @@ pass to the OPERATION."
"ls --color=never"
"ls")))
-(defun tramp-adb--gnu-switches-to-ash
- (switches)
+(defun tramp-adb--gnu-switches-to-ash (switches)
"Almquist shell can't handle multiple arguments.
Convert (\"-al\") to (\"-a\" \"-l\"). Remove arguments like \"--dired\"."
(split-string
(apply 'concat
(mapcar (lambda (s)
- (tramp-compat-replace-regexp-in-string
- "\\(.\\)" " -\\1"
- (tramp-compat-replace-regexp-in-string "^-" "" s)))
+ (replace-regexp-in-string
+ "\\(.\\)" " -\\1" (replace-regexp-in-string "^-" "" s)))
;; FIXME: Warning about removed switches (long and non-dash).
(delq nil
(mapcar
@@ -523,6 +523,9 @@ Emacs dired can't find files."
(defun tramp-adb-handle-delete-directory (directory &optional recursive)
"Like `delete-directory' for Tramp files."
(setq directory (expand-file-name directory))
+ (with-parsed-tramp-file-name (file-truename directory) nil
+ (tramp-flush-file-property v (file-name-directory localname))
+ (tramp-flush-directory-property v localname))
(with-parsed-tramp-file-name directory nil
(tramp-flush-file-property v (file-name-directory localname))
(tramp-flush-directory-property v localname)
@@ -546,7 +549,7 @@ Emacs dired can't find files."
"Like `file-name-all-completions' for Tramp files."
(all-completions
filename
- (with-parsed-tramp-file-name directory nil
+ (with-parsed-tramp-file-name (expand-file-name directory) nil
(with-tramp-file-property v localname "file-name-all-completions"
(save-match-data
(tramp-adb-send-command
@@ -572,21 +575,21 @@ Emacs dired can't find files."
(with-parsed-tramp-file-name filename nil
(unless (file-exists-p (file-truename filename))
(tramp-error
- v 'file-error
+ v tramp-file-missing
"Cannot make local copy of non-existing file `%s'" filename))
(let ((tmpfile (tramp-compat-make-temp-file filename)))
(with-tramp-progress-reporter
v 3 (format "Fetching %s to tmp file %s" filename tmpfile)
;; "adb pull ..." does not always return an error code.
- (when (or (tramp-adb-execute-adb-command v "pull" localname tmpfile)
+ (when (or (tramp-adb-execute-adb-command
+ v "pull" (tramp-compat-file-name-unquote localname) tmpfile)
(not (file-exists-p tmpfile)))
(ignore-errors (delete-file tmpfile))
(tramp-error
v 'file-error "Cannot make local copy of file `%s'" filename))
(set-file-modes
tmpfile
- (logior (or (file-modes filename) 0)
- (tramp-compat-octal-to-decimal "0400"))))
+ (logior (or (file-modes filename) 0) (string-to-number "0400" 8))))
tmpfile)))
(defun tramp-adb-handle-file-writable-p (filename)
@@ -631,8 +634,7 @@ But handle the case, if the \"test\" command is not available."
(copy-file filename tmpfile 'ok)
(set-file-modes
tmpfile
- (logior (or (file-modes tmpfile) 0)
- (tramp-compat-octal-to-decimal "0600"))))
+ (logior (or (file-modes tmpfile) 0) (string-to-number "0600" 8))))
(tramp-run-real-handler
'write-region
(list start end tmpfile append 'no-message lockname confirm))
@@ -640,7 +642,8 @@ But handle the case, if the \"test\" command is not available."
v 3 (format-message
"Moving tmp file `%s' to `%s'" tmpfile filename)
(unwind-protect
- (when (tramp-adb-execute-adb-command v "push" tmpfile localname)
+ (when (tramp-adb-execute-adb-command
+ v "push" tmpfile (tramp-compat-file-name-unquote localname))
(tramp-error v 'file-error "Cannot write: `%s'" filename))
(delete-file tmpfile)))
@@ -657,8 +660,7 @@ But handle the case, if the \"test\" command is not available."
(with-parsed-tramp-file-name filename nil
(tramp-flush-file-property v (file-name-directory localname))
(tramp-flush-file-property v localname)
- (tramp-adb-send-command-and-check
- v (format "chmod %s %s" (tramp-compat-decimal-to-octal mode) localname))))
+ (tramp-adb-send-command-and-check v (format "chmod %o %s" mode localname))))
(defun tramp-adb-handle-set-file-times (filename &optional time)
"Like `set-file-times' for Tramp files."
@@ -676,7 +678,7 @@ But handle the case, if the \"test\" command is not available."
(defun tramp-adb-handle-copy-file
(filename newname &optional ok-if-already-exists keep-date
- _preserve-uid-gid _preserve-extended-attributes)
+ _preserve-uid-gid _preserve-extended-attributes)
"Like `copy-file' for Tramp files.
PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
(setq filename (expand-file-name filename)
@@ -684,42 +686,72 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
(if (file-directory-p filename)
(tramp-file-name-handler 'copy-directory filename newname keep-date t)
- (with-tramp-progress-reporter
- (tramp-dissect-file-name
- (if (tramp-tramp-file-p filename) filename newname))
- 0 (format "Copying %s to %s" filename newname)
-
- (let ((tmpfile (file-local-copy filename)))
-
- (if tmpfile
- ;; Remote filename.
- (condition-case err
- (rename-file tmpfile newname ok-if-already-exists)
- ((error quit)
- (delete-file tmpfile)
- (signal (car err) (cdr err))))
-
- ;; Remote newname.
- (when (file-directory-p newname)
- (setq newname
- (expand-file-name (file-name-nondirectory filename) newname)))
-
- (with-parsed-tramp-file-name newname nil
- (when (and (not ok-if-already-exists)
- (file-exists-p newname))
- (tramp-error v 'file-already-exists newname))
-
- ;; We must also flush the cache of the directory, because
- ;; `file-attributes' reads the values from there.
- (tramp-flush-file-property v (file-name-directory localname))
- (tramp-flush-file-property v localname)
- (when (tramp-adb-execute-adb-command v "push" filename localname)
- (tramp-error
- v 'file-error "Cannot copy `%s' `%s'" filename newname))))))
+
+ (let ((t1 (tramp-tramp-file-p filename))
+ (t2 (tramp-tramp-file-p newname)))
+ (with-parsed-tramp-file-name (if t1 filename newname) nil
+ (with-tramp-progress-reporter
+ v 0 (format "Copying %s to %s" filename newname)
+
+ (if (and t1 t2 (tramp-equal-remote filename newname))
+ (let ((l1 (file-remote-p filename 'localname))
+ (l2 (file-remote-p newname 'localname)))
+ (when (and (not ok-if-already-exists)
+ (file-exists-p newname))
+ (tramp-error v 'file-already-exists newname))
+ ;; We must also flush the cache of the directory,
+ ;; because `file-attributes' reads the values from
+ ;; there.
+ (tramp-flush-file-property v (file-name-directory l2))
+ (tramp-flush-file-property v l2)
+ ;; Short track.
+ (tramp-adb-barf-unless-okay
+ v (format
+ "cp -f %s %s"
+ (tramp-shell-quote-argument l1)
+ (tramp-shell-quote-argument l2))
+ "Error copying %s to %s" filename newname))
+
+ (let ((tmpfile (file-local-copy filename)))
+
+ (if tmpfile
+ ;; Remote filename.
+ (condition-case err
+ (rename-file tmpfile newname ok-if-already-exists)
+ ((error quit)
+ (delete-file tmpfile)
+ (signal (car err) (cdr err))))
+
+ ;; Remote newname.
+ (when (file-directory-p newname)
+ (setq newname
+ (expand-file-name
+ (file-name-nondirectory filename) newname)))
+
+ (with-parsed-tramp-file-name newname nil
+ (when (and (not ok-if-already-exists)
+ (file-exists-p newname))
+ (tramp-error v 'file-already-exists newname))
+
+ ;; We must also flush the cache of the directory,
+ ;; because `file-attributes' reads the values from
+ ;; there.
+ (tramp-flush-file-property v (file-name-directory localname))
+ (tramp-flush-file-property v localname)
+ (when (tramp-adb-execute-adb-command
+ v "push"
+ (tramp-compat-file-name-unquote filename)
+ (tramp-compat-file-name-unquote localname))
+ (tramp-error
+ v 'file-error
+ "Cannot copy `%s' `%s'" filename newname)))))))))
;; KEEP-DATE handling.
(when keep-date
- (set-file-times newname (nth 5 (file-attributes filename))))))
+ (set-file-times
+ newname
+ (tramp-compat-file-attribute-modification-time
+ (file-attributes filename))))))
(defun tramp-adb-handle-rename-file
(filename newname &optional ok-if-already-exists)
@@ -736,10 +768,8 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
(if (and t1 t2
(tramp-equal-remote filename newname)
(not (file-directory-p filename)))
- (let ((l1 (tramp-file-name-handler
- 'file-remote-p filename 'localname))
- (l2 (tramp-file-name-handler
- 'file-remote-p newname 'localname)))
+ (let ((l1 (file-remote-p filename 'localname))
+ (l2 (file-remote-p newname 'localname)))
(when (and (not ok-if-already-exists)
(file-exists-p newname))
(tramp-error v 'file-already-exists newname))
@@ -751,11 +781,15 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
(tramp-flush-file-property v l2)
;; Short track.
(tramp-adb-barf-unless-okay
- v (format "mv %s %s" l1 l2)
+ v (format
+ "mv -f %s %s"
+ (tramp-shell-quote-argument l1)
+ (tramp-shell-quote-argument l2))
"Error renaming %s to %s" filename newname))
;; Rename by copy.
- (copy-file filename newname ok-if-already-exists t t)
+ (copy-file
+ filename newname ok-if-already-exists 'keep-time 'preserve-uid-gid)
(delete-file filename))))))
(defun tramp-adb-handle-process-file
@@ -856,12 +890,7 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
;; because the remote process could have changed them.
(when tmpinput (delete-file tmpinput))
- ;; `process-file-side-effects' has been introduced with GNU
- ;; Emacs 23.2. If set to nil, no remote file will be changed
- ;; by `program'. If it doesn't exist, we assume its default
- ;; value t.
- (unless (and (boundp 'process-file-side-effects)
- (not (symbol-value 'process-file-side-effects)))
+ (unless process-file-side-effects
(tramp-flush-directory-property v ""))
;; Return exit status.
@@ -904,7 +933,7 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
(when p
(if (yes-or-no-p "A command is running. Kill it? ")
(ignore-errors (kill-process p))
- (tramp-user-error p "Shell command in progress")))
+ (tramp-compat-user-error p "Shell command in progress")))
(if current-buffer-p
(progn
@@ -941,9 +970,7 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
(current-buffer))))
;; There's some output, display it.
(when (with-current-buffer output-buffer (> (point-max) (point-min)))
- (if (functionp 'display-message-or-buffer)
- (tramp-compat-funcall 'display-message-or-buffer output-buffer)
- (pop-to-buffer output-buffer))))))))
+ (display-message-or-buffer output-buffer)))))))
;; We use BUFFER also as connection buffer during setup. Because of
;; this, its original contents must be saved, and restored once
@@ -956,20 +983,22 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
(unless (stringp program)
(tramp-error v 'file-error "PROGRAM must be a string"))
- (let ((command
- (format "cd %s; %s"
- (tramp-shell-quote-argument localname)
- (mapconcat 'tramp-shell-quote-argument
- (cons program args) " ")))
- (tramp-process-connection-type
- (or (null program) tramp-process-connection-type))
- (bmp (and (buffer-live-p buffer) (buffer-modified-p buffer)))
- (name1 name)
- (i 0))
-
- (unless buffer
- ;; BUFFER can be nil. We use a temporary buffer.
- (setq buffer (generate-new-buffer tramp-temp-buffer-name)))
+ (let* ((buffer
+ (if buffer
+ (get-buffer-create buffer)
+ ;; BUFFER can be nil. We use a temporary buffer.
+ (generate-new-buffer tramp-temp-buffer-name)))
+ (command
+ (format "cd %s; %s"
+ (tramp-shell-quote-argument localname)
+ (mapconcat 'tramp-shell-quote-argument
+ (cons program args) " ")))
+ (tramp-process-connection-type
+ (or (null program) tramp-process-connection-type))
+ (bmp (and (buffer-live-p buffer) (buffer-modified-p buffer)))
+ (name1 name)
+ (i 0))
+
(while (get-process name1)
;; NAME must be unique as process name.
(setq i (1+ i)
@@ -1008,7 +1037,7 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
;; process. We ignore errors, because the process
;; could have finished already.
(ignore-errors
- (tramp-compat-set-process-query-on-exit-flag p t)
+ (set-process-query-on-exit-flag p t)
(set-marker (process-mark p) (point)))
;; Return process.
p))))
@@ -1035,7 +1064,7 @@ E.g. a host name \"192.168.1.1#5555\" returns \"192.168.1.1:5555\"
(host (tramp-file-name-host vec))
(port (tramp-file-name-port vec))
(devices (mapcar 'cadr (tramp-adb-parse-device-names nil))))
- (tramp-compat-replace-regexp-in-string
+ (replace-regexp-in-string
tramp-prefix-port-format ":"
(cond ((member host devices) host)
;; This is the case when the host is connected to the default port.
@@ -1051,7 +1080,7 @@ E.g. a host name \"192.168.1.1#5555\" returns \"192.168.1.1:5555\"
(not (zerop (length host)))
(not (tramp-adb-execute-adb-command
vec "connect"
- (tramp-compat-replace-regexp-in-string
+ (replace-regexp-in-string
tramp-prefix-port-format ":" host))))
;; When new device connected, running other adb command (e.g.
;; adb shell) immediately will fail. To get around this
@@ -1065,7 +1094,7 @@ E.g. a host name \"192.168.1.1#5555\" returns \"192.168.1.1:5555\"
"Returns nil on success error-output on failure."
(when (and (> (length (tramp-file-name-host vec)) 0)
;; The -s switch is only available for ADB device commands.
- (not (member (car args) (list "connect" "disconnect"))))
+ (not (member (car args) '("connect" "disconnect"))))
(setq args (append (list "-s" (tramp-adb-get-device vec)) args)))
(with-temp-buffer
(prog1
@@ -1102,8 +1131,7 @@ This happens for Android >= 4.0."
(while (re-search-forward "\r+$" nil t)
(replace-match "" nil nil)))))
-(defun tramp-adb-send-command-and-check
- (vec command)
+(defun tramp-adb-send-command-and-check (vec command)
"Run COMMAND and check its exit status.
Sends `echo $?' along with the COMMAND for checking the exit
status. If COMMAND is nil, just sends `echo $?'. Returns nil if
@@ -1182,8 +1210,7 @@ connection if a previous connection has died for some reason."
(when (and user (not (tramp-get-file-property vec "" "su-command-p" t)))
(tramp-error vec 'file-error "Cannot switch to user `%s'" user))
- (unless
- (and p (processp p) (memq (process-status p) '(run open)))
+ (unless (tramp-compat-process-live-p p)
(save-match-data
(when (and p (processp p)) (delete-process p))
(if (zerop (length device))
@@ -1202,10 +1229,10 @@ connection if a previous connection has died for some reason."
vec 6 "%s" (mapconcat 'identity (process-command p) " "))
;; Wait for initial prompt.
(tramp-adb-wait-for-output p 30)
- (unless (eq 'run (process-status p))
+ (unless (tramp-compat-process-live-p p)
(tramp-error vec 'file-error "Terminated!"))
(tramp-set-connection-property p "vector" vec)
- (tramp-compat-set-process-query-on-exit-flag p nil)
+ (set-process-query-on-exit-flag p nil)
;; Check whether the properties have been changed. If
;; yes, this is a strong indication that we must expire all
@@ -1250,7 +1277,10 @@ connection if a previous connection has died for some reason."
;; Read the expression.
(goto-char (point-min))
(read (current-buffer)))
- ":" 'omit-nulls))
+ ":" 'omit))
+
+ ;; Set connection-local variables.
+ (tramp-set-connection-local-variables vec)
;; Mark it as connected.
(tramp-set-connection-property p "connected" t)))))))
diff --git a/lisp/net/tramp-cache.el b/lisp/net/tramp-cache.el
index 26825ffa2dd..0d90017651b 100644
--- a/lisp/net/tramp-cache.el
+++ b/lisp/net/tramp-cache.el
@@ -72,31 +72,16 @@ details see the info pages."
:version "24.4"
:type '(repeat (list (choice :tag "File Name regexp" regexp (const nil))
(choice :tag " Property" string)
- (choice :tag " Value" sexp))))
+ (choice :tag " Value" sexp)))
+ :require 'tramp)
+;;;###tramp-autoload
(defcustom tramp-persistency-file-name
- (cond
- ;; GNU Emacs.
- ((and (fboundp 'locate-user-emacs-file))
- (expand-file-name (tramp-compat-funcall 'locate-user-emacs-file "tramp")))
- ((and (boundp 'user-emacs-directory)
- (stringp (symbol-value 'user-emacs-directory))
- (file-directory-p (symbol-value 'user-emacs-directory)))
- (expand-file-name "tramp" (symbol-value 'user-emacs-directory)))
- ((and (not (featurep 'xemacs)) (file-directory-p "~/.emacs.d/"))
- "~/.emacs.d/tramp")
- ;; XEmacs.
- ((and (boundp 'user-init-directory)
- (stringp (symbol-value 'user-init-directory))
- (file-directory-p (symbol-value 'user-init-directory)))
- (expand-file-name "tramp" (symbol-value 'user-init-directory)))
- ((and (featurep 'xemacs) (file-directory-p "~/.xemacs/"))
- "~/.xemacs/tramp")
- ;; For users without `~/.emacs.d/' or `~/.xemacs/'.
- (t "~/.tramp"))
+ (expand-file-name (locate-user-emacs-file "tramp"))
"File which keeps connection history for Tramp connections."
:group 'tramp
- :type 'file)
+ :type 'file
+ :require 'tramp)
(defvar tramp-cache-data-changed nil
"Whether persistent cache data have been changed.")
@@ -122,6 +107,7 @@ matching entries of `tramp-connection-properties'."
"Get the PROPERTY of FILE from the cache context of KEY.
Returns DEFAULT if not set."
;; Unify localname. Remove hop from vector.
+ (setq file (tramp-compat-file-name-unquote file))
(setq key (copy-sequence key))
(aset key 3 (tramp-run-real-handler 'directory-file-name (list file)))
(aset key 4 nil)
@@ -155,6 +141,7 @@ Returns DEFAULT if not set."
"Set the PROPERTY of FILE to VALUE, in the cache context of KEY.
Returns VALUE."
;; Unify localname. Remove hop from vector.
+ (setq file (tramp-compat-file-name-unquote file))
(setq key (copy-sequence key))
(aset key 3 (tramp-run-real-handler 'directory-file-name (list file)))
(aset key 4 nil)
@@ -174,28 +161,26 @@ Returns VALUE."
(let* ((file (tramp-run-real-handler
'directory-file-name (list file)))
(truename (tramp-get-file-property key file "file-truename" nil)))
- ;; Remove file properties of symlinks.
- (when (and (stringp truename)
- (not (string-equal file (directory-file-name truename))))
- (tramp-flush-file-property key truename))
;; Unify localname. Remove hop from vector.
+ (setq file (tramp-compat-file-name-unquote file))
(setq key (copy-sequence key))
(aset key 3 file)
(aset key 4 nil)
(tramp-message key 8 "%s" file)
- (remhash key tramp-cache-data)))
+ (remhash key tramp-cache-data)
+ ;; Remove file properties of symlinks.
+ (when (and (stringp truename)
+ (not (string-equal file (directory-file-name truename))))
+ (tramp-flush-file-property key truename))))
;;;###tramp-autoload
(defun tramp-flush-directory-property (key directory)
"Remove all properties of DIRECTORY in the cache context of KEY.
Remove also properties of all files in subdirectories."
+ (setq directory (tramp-compat-file-name-unquote directory))
(let* ((directory (tramp-run-real-handler
'directory-file-name (list directory)))
(truename (tramp-get-file-property key directory "file-truename" nil)))
- ;; Remove file properties of symlinks.
- (when (and (stringp truename)
- (not (string-equal directory (directory-file-name truename))))
- (tramp-flush-directory-property key truename))
(tramp-message key 8 "%s" directory)
(maphash
(lambda (key _value)
@@ -203,7 +188,11 @@ Remove also properties of all files in subdirectories."
(string-match (regexp-quote directory)
(tramp-file-name-localname key)))
(remhash key tramp-cache-data)))
- tramp-cache-data)))
+ tramp-cache-data)
+ ;; Remove file properties of symlinks.
+ (when (and (stringp truename)
+ (not (string-equal directory (directory-file-name truename))))
+ (tramp-flush-directory-property key truename))))
;; Reverting or killing a buffer should also flush file properties.
;; They could have been changed outside Tramp. In eshell, "ls" would
@@ -241,8 +230,10 @@ This is suppressed for temporary buffers."
;;;###tramp-autoload
(defun tramp-get-connection-property (key property default)
"Get the named PROPERTY for the connection.
-KEY identifies the connection, it is either a process or a vector.
-If the value is not set for the connection, returns DEFAULT."
+KEY identifies the connection, it is either a process or a
+vector. A special case is nil, which is used to cache connection
+properties of the local machine. If the value is not set for the
+connection, returns DEFAULT."
;; Unify key by removing localname and hop from vector. Work with a
;; copy in order to avoid side effects.
(when (vectorp key)
@@ -250,17 +241,24 @@ If the value is not set for the connection, returns DEFAULT."
(aset key 3 nil)
(aset key 4 nil))
(let* ((hash (tramp-get-hash-table key))
- (value (if (hash-table-p hash)
- (gethash property hash default)
- default)))
+ (value
+ ;; If the key is an auxiliary process object, check whether
+ ;; the process is still alive.
+ (if (and (processp key) (not (tramp-compat-process-live-p key)))
+ default
+ (if (hash-table-p hash)
+ (gethash property hash default)
+ default))))
(tramp-message key 7 "%s %s" property value)
value))
;;;###tramp-autoload
(defun tramp-set-connection-property (key property value)
"Set the named PROPERTY of a connection to VALUE.
-KEY identifies the connection, it is either a process or a vector.
-PROPERTY is set persistent when KEY is a vector."
+KEY identifies the connection, it is either a process or a
+vector. A special case is nil, which is used to cache connection
+properties of the local machine. PROPERTY is set persistent when
+KEY is a vector."
;; Unify key by removing localname and hop from vector. Work with a
;; copy in order to avoid side effects.
(when (vectorp key)
@@ -276,13 +274,17 @@ PROPERTY is set persistent when KEY is a vector."
;;;###tramp-autoload
(defun tramp-connection-property-p (key property)
"Check whether named PROPERTY of a connection is defined.
-KEY identifies the connection, it is either a process or a vector."
+KEY identifies the connection, it is either a process or a
+vector. A special case is nil, which is used to cache connection
+properties of the local machine."
(not (eq (tramp-get-connection-property key property 'undef) 'undef)))
;;;###tramp-autoload
(defun tramp-flush-connection-property (key)
"Remove all properties identified by KEY.
-KEY identifies the connection, it is either a process or a vector."
+KEY identifies the connection, it is either a process or a
+vector. A special case is nil, which is used to cache connection
+properties of the local machine."
;; Unify key by removing localname and hop from vector. Work with a
;; copy in order to avoid side effects.
(when (vectorp key)
@@ -307,19 +309,14 @@ KEY identifies the connection, it is either a process or a vector."
(maphash
(lambda (key value)
;; Remove text properties from KEY and VALUE.
- ;; `substring-no-properties' does not exist in XEmacs.
- (when (functionp 'substring-no-properties)
- (when (vectorp key)
- (dotimes (i (length key))
- (when (stringp (aref key i))
- (aset key i
- (tramp-compat-funcall
- 'substring-no-properties (aref key i))))))
- (when (stringp key)
- (setq key (tramp-compat-funcall 'substring-no-properties key)))
- (when (stringp value)
- (setq value
- (tramp-compat-funcall 'substring-no-properties value))))
+ (when (vectorp key)
+ (dotimes (i (length key))
+ (when (stringp (aref key i))
+ (aset key i (substring-no-properties (aref key i))))))
+ (when (stringp key)
+ (setq key (substring-no-properties key)))
+ (when (stringp value)
+ (setq value (substring-no-properties value)))
;; Dump.
(let ((tmp (format
"(%s %s)"
@@ -338,17 +335,18 @@ KEY identifies the connection, it is either a process or a vector."
;;;###tramp-autoload
(defun tramp-list-connections ()
"Return a list of all known connection vectors according to `tramp-cache'."
- (let (result)
+ (let (result tramp-verbose)
(maphash
(lambda (key _value)
- (when (and (vectorp key) (null (aref key 3)))
+ (when (and (vectorp key) (null (aref key 3))
+ (tramp-connection-property-p key "process-buffer"))
(add-to-list 'result key)))
tramp-cache-data)
result))
(defun tramp-dump-connection-properties ()
"Write persistent connection properties into file `tramp-persistency-file-name'."
- ;; We shouldn't fail, otherwise (X)Emacs might not be able to be closed.
+ ;; We shouldn't fail, otherwise Emacs might not be able to be closed.
(ignore-errors
(when (and (hash-table-p tramp-cache-data)
(not (zerop (hash-table-count tramp-cache-data)))
@@ -375,7 +373,7 @@ KEY identifies the connection, it is either a process or a vector."
(with-temp-file tramp-persistency-file-name
(insert
";; -*- emacs-lisp -*-"
- ;; `time-stamp-string' might not exist in all (X)Emacs flavors.
+ ;; `time-stamp-string' might not exist in all Emacs flavors.
(condition-case nil
(progn
(format
@@ -418,8 +416,8 @@ for all methods. Resulting data are derived from connection history."
;; When "emacs -Q" has been called, both variables are nil.
;; We do not load the persistency file then, in order to
;; have a clean test environment.
- (or (and (boundp 'init-file-user) (symbol-value 'init-file-user))
- (and (boundp 'site-run-file) (symbol-value 'site-run-file))))
+ (or init-file-user
+ site-run-file))
(condition-case err
(with-temp-buffer
(insert-file-contents tramp-persistency-file-name)
diff --git a/lisp/net/tramp-cmds.el b/lisp/net/tramp-cmds.el
index e7901bb7861..208859dbe7f 100644
--- a/lisp/net/tramp-cmds.el
+++ b/lisp/net/tramp-cmds.el
@@ -31,6 +31,9 @@
(require 'tramp)
;; Pacify byte-compiler.
+(declare-function mml-mode "mml")
+(declare-function mml-insert-empty-tag "mml")
+(declare-function reporter-dump-variable "reporter")
(defvar reporter-eval-buffer)
(defvar reporter-prompt-for-summary-p)
@@ -98,8 +101,8 @@ When called interactively, a Tramp connection has to be selected."
;; Flush connection cache.
(when (processp (tramp-get-connection-process vec))
- (delete-process (tramp-get-connection-process vec))
- (tramp-flush-connection-property (tramp-get-connection-process vec)))
+ (tramp-flush-connection-property (tramp-get-connection-process vec))
+ (delete-process (tramp-get-connection-process vec)))
(tramp-flush-connection-property vec)
;; Remove buffers.
@@ -128,7 +131,7 @@ This includes password cache, file cache, connection cache, buffers."
(setq tramp-locked nil)
;; Flush password cache.
- (tramp-compat-funcall 'password-reset)
+ (password-reset)
;; Flush file and connection cache.
(clrhash tramp-cache-data)
@@ -142,7 +145,7 @@ This includes password cache, file cache, connection cache, buffers."
"Kill all remote buffers."
(interactive)
- ;; Remove all Tramp related buffers.
+ ;; Remove all Tramp related connections.
(tramp-cleanup-all-connections)
;; Remove all buffers with a remote default-directory.
@@ -166,7 +169,6 @@ This includes password cache, file cache, connection cache, buffers."
(defun tramp-bug ()
"Submit a bug report to the Tramp developers."
(interactive)
- (require 'reporter)
(catch 'dont-send
(let ((reporter-prompt-for-summary-p t))
(reporter-submit-bug-report
@@ -185,17 +187,17 @@ This includes password cache, file cache, connection cache, buffers."
backup-by-copying-when-mismatch
backup-by-copying-when-privileged-mismatch
backup-directory-alist
- bkup-backup-directory-info
password-cache
password-cache-expiry
remote-file-name-inhibit-cache
+ connection-local-class-alist
+ connection-local-criteria-alist
file-name-handler-alist))))
(lambda (x y) (string< (symbol-name (car x)) (symbol-name (car y)))))
'tramp-load-report-modules ; pre-hook
'tramp-append-tramp-buffers ; post-hook
- (tramp-compat-funcall
- (if (functionp 'propertize) 'propertize 'progn)
+ (propertize
"\n" 'display "\
Enter your bug report in this message, including as much detail
as you possibly can about the problem, what you did to cause it
@@ -243,7 +245,7 @@ buffer in your bug report.
(base64-encode-string (encode-coding-string val 'raw-text)))))))
;; Dump variable.
- (tramp-compat-funcall 'reporter-dump-variable varsym mailbuf)
+ (reporter-dump-variable varsym mailbuf)
(unless (hash-table-p val)
;; Remove string quotation.
@@ -264,15 +266,8 @@ buffer in your bug report.
(defun tramp-load-report-modules ()
"Load needed modules for reporting."
- ;; We load message.el and mml.el from Gnus.
- (if (featurep 'xemacs)
- (progn
- (load "message" 'noerror)
- (load "mml" 'noerror))
- (require 'message nil 'noerror)
- (require 'mml nil 'noerror))
- (tramp-compat-funcall 'message-mode)
- (tramp-compat-funcall 'mml-mode t))
+ (message-mode)
+ (mml-mode t))
(defun tramp-append-tramp-buffers ()
"Append Tramp buffers and buffer local variables into the bug report."
@@ -301,9 +296,9 @@ buffer in your bug report.
'intern
(all-completions "tramp-" (buffer-local-variables buffer)))
;; Non-tramp variables of interest.
- '(default-directory))
+ '(connection-local-variables-alist default-directory))
'string<))
- (tramp-compat-funcall 'reporter-dump-variable varsym elbuf))
+ (reporter-dump-variable varsym elbuf))
(lisp-indent-line)
(insert ")\n"))
(insert-buffer-substring elbuf)))
@@ -313,7 +308,7 @@ buffer in your bug report.
(ignore-errors
(mapc
(lambda (x) (when (string-match "tramp" x) (insert x "\n")))
- (split-string (tramp-compat-funcall 'list-load-path-shadows t) "\n")))
+ (split-string (list-load-path-shadows t) "\n")))
;; Append buffers only when we are in message mode.
(when (and
@@ -322,7 +317,7 @@ buffer in your bug report.
(symbol-value 'mml-mode))
(let ((tramp-buf-regexp "\\*\\(debug \\)?tramp/")
- (buffer-list (tramp-compat-funcall 'tramp-list-tramp-buffers))
+ (buffer-list (tramp-list-tramp-buffers))
(curbuf (current-buffer)))
;; There is at least one Tramp buffer.
@@ -352,7 +347,7 @@ names. Passwords will never be included there.")
Please note that you have set `tramp-verbose' to a value of at
least 6. Therefore, the contents of files might be included in
the debug buffer(s).")
- (add-text-properties start (point) (list 'face 'italic))))
+ (add-text-properties start (point) '(face italic))))
(set-buffer-modified-p nil)
(setq buffer-read-only t)
@@ -364,13 +359,13 @@ the debug buffer(s).")
(kill-buffer nil)
(switch-to-buffer curbuf)
(goto-char (point-max))
- (insert (tramp-compat-funcall 'propertize "\n" 'display "\n\
+ (insert (propertize "\n" 'display "\n\
This is a special notion of the `gnus/message' package. If you
use another mail agent (by copying the contents of this buffer)
please ensure that the buffers are attached to your email.\n\n"))
(dolist (buffer buffer-list)
- (tramp-compat-funcall
- 'mml-insert-empty-tag 'part 'type "text/plain"
+ (mml-insert-empty-tag
+ 'part 'type "text/plain"
'encoding "base64" 'disposition "attachment" 'buffer buffer
'description buffer))
(set-buffer-modified-p nil))
@@ -391,10 +386,12 @@ please ensure that the buffers are attached to your email.\n\n"))
;;; TODO:
;; * Clean up unused *tramp/foo* buffers after a while. (Pete Forman)
+;;
;; * WIBNI there was an interactive command prompting for Tramp
;; method, hostname, username and filename and translates the user
;; input into the correct filename syntax (depending on the Emacs
;; flavor) (Reiner Steib)
+;;
;; * Let the user edit the connection properties interactively.
;; Something like `gnus-server-edit-server' in Gnus' *Server* buffer.
diff --git a/lisp/net/tramp-compat.el b/lisp/net/tramp-compat.el
index 44923aee895..9b779a0566b 100644
--- a/lisp/net/tramp-compat.el
+++ b/lisp/net/tramp-compat.el
@@ -23,9 +23,9 @@
;;; Commentary:
-;; Tramp's main Emacs version for development is Emacs 24. This
-;; package provides compatibility functions for Emacs 22, Emacs 23,
-;; XEmacs 21.4+ and SXEmacs 22.
+;; Tramp's main Emacs version for development is Emacs 26. This
+;; package provides compatibility functions for Emacs 23, Emacs 24 and
+;; Emacs 25.
;;; Code:
@@ -33,164 +33,59 @@
(eval-when-compile
(require 'cl))
-(eval-and-compile
-
- ;; GNU Emacs 22.
- (unless (fboundp 'ignore-errors)
- (load "cl" 'noerror)
- (load "cl-macs" 'noerror))
-
- ;; Some packages must be required for XEmacs, because we compile
- ;; with -no-autoloads.
- (when (featurep 'xemacs)
- (require 'cus-edit)
- (require 'env)
- (require 'executable)
- (require 'outline)
- (require 'passwd)
- (require 'pp)
- (require 'regexp-opt)
- (require 'time-date))
-
- (require 'advice)
- (require 'custom)
- (require 'format-spec)
- (require 'shell)
- ;; Introduced in Emacs 23.2.
- (require 'ucs-normalize nil 'noerror)
-
- (require 'trampver)
- (require 'tramp-loaddefs)
-
- ;; As long as password.el is not part of (X)Emacs, it shouldn't be
- ;; mandatory.
- (if (featurep 'xemacs)
- (load "password" 'noerror)
- (or (require 'password-cache nil 'noerror)
- (require 'password nil 'noerror))) ; Part of contrib.
-
- ;; auth-source is relatively new.
- (if (featurep 'xemacs)
- (load "auth-source" 'noerror)
- (require 'auth-source nil 'noerror))
-
- ;; Load the appropriate timer package.
- (if (featurep 'xemacs)
- (require 'timer-funcs)
- (require 'timer))
-
- ;; Avoid byte-compiler warnings if the byte-compiler supports this.
- ;; Currently, XEmacs supports this.
- (when (featurep 'xemacs)
- (unless (boundp 'byte-compile-default-warnings)
- (defvar byte-compile-default-warnings nil))
- (delq 'unused-vars byte-compile-default-warnings))
-
- ;; `last-coding-system-used' is unknown in XEmacs.
- (unless (boundp 'last-coding-system-used)
- (defvar last-coding-system-used nil))
-
- ;; `directory-sep-char' is an obsolete variable in Emacs. But it is
- ;; used in XEmacs, so we set it here and there. The following is
- ;; needed to pacify Emacs byte-compiler.
- ;; Note that it was removed altogether in Emacs 24.1.
- (when (boundp 'directory-sep-char)
- (defvar byte-compile-not-obsolete-var nil)
- (setq byte-compile-not-obsolete-var 'directory-sep-char)
- ;; Emacs 23.2.
- (defvar byte-compile-not-obsolete-vars nil)
- (setq byte-compile-not-obsolete-vars '(directory-sep-char)))
-
- ;; `remote-file-name-inhibit-cache' has been introduced with Emacs 24.1.
- ;; Besides t, nil, and integer, we use also timestamps (as
- ;; returned by `current-time') internally.
- (unless (boundp 'remote-file-name-inhibit-cache)
- (defvar remote-file-name-inhibit-cache nil))
-
- ;; For not existing functions, or functions with a changed argument
- ;; list, there are compiler warnings. We want to avoid them in
- ;; cases we know what we do.
- (defmacro tramp-compat-funcall (function &rest arguments)
- (if (featurep 'xemacs)
- `(funcall (symbol-function ,function) ,@arguments)
- `(when (or (subrp ,function) (functionp ,function))
- (with-no-warnings (funcall ,function ,@arguments)))))
-
- ;; `set-buffer-multibyte' comes from Emacs Leim.
- (unless (fboundp 'set-buffer-multibyte)
- (defalias 'set-buffer-multibyte 'ignore))
-
- ;; The following functions cannot be aliases of the corresponding
- ;; `tramp-handle-*' functions, because this would bypass the locking
- ;; mechanism.
-
- ;; `process-file' does not exist in XEmacs.
- (unless (fboundp 'process-file)
- (defalias 'process-file
- (lambda (program &optional infile buffer display &rest args)
- (when (tramp-tramp-file-p default-directory)
- (apply
- 'tramp-file-name-handler
- 'process-file program infile buffer display args)))))
-
- ;; `start-file-process' is new in Emacs 23.
- (unless (fboundp 'start-file-process)
- (defalias 'start-file-process
- (lambda (name buffer program &rest program-args)
- (when (tramp-tramp-file-p default-directory)
- (apply
- 'tramp-file-name-handler
- 'start-file-process name buffer program program-args)))))
-
- ;; `set-file-times' is also new in Emacs 23.
- (unless (fboundp 'set-file-times)
- (defalias 'set-file-times
- (lambda (filename &optional time)
- (when (tramp-tramp-file-p filename)
- (tramp-compat-funcall
- 'tramp-file-name-handler 'set-file-times filename time)))))
-
- ;; We currently use "[" and "]" in the filename format for IPv6
- ;; hosts of GNU Emacs. This means that Emacs wants to expand
- ;; wildcards if `find-file-wildcards' is non-nil, and then barfs
- ;; because no expansion could be found. We detect this situation
- ;; and do something really awful: we have `file-expand-wildcards'
- ;; return the original filename if it can't expand anything. Let's
- ;; just hope that this doesn't break anything else.
- ;; It is not needed anymore since GNU Emacs 23.2.
- (unless (or (featurep 'xemacs)
- ;; `featurep' has only one argument in XEmacs.
- (funcall 'featurep 'files 'remote-wildcards))
- (defadvice file-expand-wildcards
+(require 'auth-source)
+(require 'advice)
+(require 'custom)
+(require 'format-spec)
+(require 'parse-time)
+(require 'password-cache)
+(require 'shell)
+(require 'timer)
+(require 'ucs-normalize)
+
+(require 'trampver)
+(require 'tramp-loaddefs)
+
+;; `remote-file-name-inhibit-cache' has been introduced with Emacs
+;; 24.1. Besides t, nil, and integer, we use also timestamps (as
+;; returned by `current-time') internally.
+(unless (boundp 'remote-file-name-inhibit-cache)
+ (defvar remote-file-name-inhibit-cache nil))
+
+;; For not existing functions, obsolete functions, or functions with a
+;; changed argument list, there are compiler warnings. We want to
+;; avoid them in cases we know what we do.
+(defmacro tramp-compat-funcall (function &rest arguments)
+ "Call FUNCTION if it exists. Do not raise compiler warnings."
+ `(when (functionp ,function)
+ (with-no-warnings (funcall ,function ,@arguments))))
+
+;; We currently use "[" and "]" in the filename format for IPv6 hosts
+;; of GNU Emacs. This means that Emacs wants to expand wildcards if
+;; `find-file-wildcards' is non-nil, and then barfs because no
+;; expansion could be found. We detect this situation and do
+;; something really awful: we have `file-expand-wildcards' return the
+;; original filename if it can't expand anything. Let's just hope
+;; that this doesn't break anything else. It is not needed anymore
+;; since GNU Emacs 23.2.
+(unless (featurep 'files 'remote-wildcards)
+ (defadvice file-expand-wildcards
(around tramp-advice-file-expand-wildcards activate)
- (let ((name (ad-get-arg 0)))
- ;; If it's a Tramp file, look if wildcards need to be expanded
- ;; at all.
- (if (and
- (tramp-tramp-file-p name)
- (not (string-match
- "[[*?]" (tramp-compat-funcall
- 'file-remote-p name 'localname))))
- (setq ad-return-value (list name))
- ;; Otherwise, just run the original function.
- ad-do-it)))
- (add-hook
- 'tramp-unload-hook
- (lambda ()
- (ad-remove-advice
- 'file-expand-wildcards 'around 'tramp-advice-file-expand-wildcards)
- (ad-activate 'file-expand-wildcards))))
-
- ;; `redisplay' does not exist in XEmacs.
- (unless (fboundp 'redisplay)
- (defalias 'redisplay 'ignore)))
-
-;; `with-temp-message' does not exist in XEmacs.
-(if (fboundp 'with-temp-message)
- (defalias 'tramp-compat-with-temp-message 'with-temp-message)
- (defmacro tramp-compat-with-temp-message (_message &rest body)
- "Display MESSAGE temporarily if non-nil while BODY is evaluated."
- `(progn ,@body)))
+ (let ((name (ad-get-arg 0)))
+ ;; If it's a Tramp file, look if wildcards need to be expanded
+ ;; at all.
+ (if (and
+ (tramp-tramp-file-p name)
+ (not (string-match "[[*?]" (file-remote-p name 'localname))))
+ (setq ad-return-value (list name))
+ ;; Otherwise, just run the original function.
+ ad-do-it)))
+ (add-hook
+ 'tramp-unload-hook
+ (lambda ()
+ (ad-remove-advice
+ 'file-expand-wildcards 'around 'tramp-advice-file-expand-wildcards)
+ (ad-activate 'file-expand-wildcards))))
;; `condition-case-unless-debug' is introduced with Emacs 24.
(if (fboundp 'condition-case-unless-debug)
@@ -208,110 +103,34 @@
(funcall ,bodysym)
,@handlers))))))
-;; `font-lock-add-keywords' does not exist in XEmacs.
-(defun tramp-compat-font-lock-add-keywords (mode keywords &optional how)
- "Add highlighting KEYWORDS for MODE."
- (ignore-errors
- (tramp-compat-funcall 'font-lock-add-keywords mode keywords how)))
-
(defsubst tramp-compat-temporary-file-directory ()
- "Return name of directory for temporary files (compat function).
-For Emacs, this is the variable `temporary-file-directory', for XEmacs
-this is the function `temp-directory'."
- (let (file-name-handler-alist)
- ;; We must return a local directory. If it is remote, we could
- ;; run into an infloop.
- (cond
- ((and (boundp 'temporary-file-directory)
- (eval (car (get 'temporary-file-directory 'standard-value)))))
- ((fboundp 'temp-directory) (tramp-compat-funcall 'temp-directory))
- ((let ((d (getenv "TEMP"))) (and d (file-directory-p d)))
- (file-name-as-directory (getenv "TEMP")))
- ((let ((d (getenv "TMP"))) (and d (file-directory-p d)))
- (file-name-as-directory (getenv "TMP")))
- ((let ((d (getenv "TMPDIR"))) (and d (file-directory-p d)))
- (file-name-as-directory (getenv "TMPDIR")))
- ((file-exists-p "c:/temp") (file-name-as-directory "c:/temp"))
- (t (message (concat "Neither `temporary-file-directory' nor "
- "`temp-directory' is defined -- using /tmp."))
- (file-name-as-directory "/tmp")))))
-
-;; `make-temp-file' exists in Emacs only. On XEmacs, we use our own
-;; implementation with `make-temp-name', creating the temporary file
-;; immediately in order to avoid a security hole.
+ "Return name of directory for temporary files.
+It is the default value of `temporary-file-directory'."
+ ;; We must return a local directory. If it is remote, we could run
+ ;; into an infloop.
+ (eval (car (get 'temporary-file-directory 'standard-value))))
+
(defsubst tramp-compat-make-temp-file (f &optional dir-flag)
- "Create a temporary file (compat function).
+ "Create a local temporary file (compat function).
Add the extension of F, if existing."
(let* (file-name-handler-alist
(prefix (expand-file-name
(symbol-value 'tramp-temp-name-prefix)
(tramp-compat-temporary-file-directory)))
- (extension (file-name-extension f t))
- result)
- (condition-case nil
- (setq result
- (tramp-compat-funcall 'make-temp-file prefix dir-flag extension))
- (error
- ;; We use our own implementation, taken from files.el.
- (while
- (condition-case ()
- (progn
- (setq result (concat (make-temp-name prefix) extension))
- (if dir-flag
- (make-directory result)
- (write-region "" nil result nil 'silent))
- nil)
- (file-already-exists t))
- ;; The file was somehow created by someone else between
- ;; `make-temp-name' and `write-region', let's try again.
- nil)))
- result))
-
-;; `most-positive-fixnum' does not exist in XEmacs.
-(defsubst tramp-compat-most-positive-fixnum ()
- "Return largest positive integer value (compat function)."
- (cond
- ((boundp 'most-positive-fixnum) (symbol-value 'most-positive-fixnum))
- ;; Default value in XEmacs.
- (t 134217727)))
-
-(defun tramp-compat-decimal-to-octal (i)
- "Return a string consisting of the octal digits of I.
-Not actually used. Use `(format \"%o\" i)' instead?"
- (cond ((< i 0) (error "Cannot convert negative number to octal"))
- ((not (integerp i)) (error "Cannot convert non-integer to octal"))
- ((zerop i) "0")
- (t (concat (tramp-compat-decimal-to-octal (/ i 8))
- (number-to-string (% i 8))))))
-
-;; Kudos to Gerd Moellmann for this suggestion.
-(defun tramp-compat-octal-to-decimal (ostr)
- "Given a string of octal digits, return a decimal number."
- (let ((x (or ostr "")))
- ;; `save-match' is in `tramp-mode-string-to-int' which calls this.
- (unless (string-match "\\`[0-7]*\\'" x)
- (error "Non-octal junk in string `%s'" x))
- (string-to-number ostr 8)))
-
-;; ID-FORMAT does not exist in XEmacs.
-(defun tramp-compat-file-attributes (filename &optional id-format)
- "Like `file-attributes' for Tramp files (compat function)."
- (cond
- ((or (null id-format) (eq id-format 'integer))
- (file-attributes filename))
- ((tramp-tramp-file-p filename)
- (tramp-compat-funcall
- 'tramp-file-name-handler 'file-attributes filename id-format))
- (t (condition-case nil
- (tramp-compat-funcall 'file-attributes filename id-format)
- (wrong-number-of-arguments (file-attributes filename))))))
-
-;; PRESERVE-UID-GID does not exist in XEmacs.
+ (extension (file-name-extension f t)))
+ (make-temp-file prefix dir-flag extension)))
+
+;; `temporary-file-directory' as function is introduced with Emacs 26.1.
+(defalias 'tramp-compat-temporary-file-directory-function
+ (if (fboundp 'temporary-file-directory)
+ 'temporary-file-directory
+ 'tramp-handle-temporary-file-directory))
+
;; PRESERVE-EXTENDED-ATTRIBUTES has been introduced with Emacs 24.1
;; (as PRESERVE-SELINUX-CONTEXT), and renamed in Emacs 24.3.
(defun tramp-compat-copy-file
(filename newname &optional ok-if-already-exists keep-date
- preserve-uid-gid preserve-extended-attributes)
+ preserve-uid-gid preserve-extended-attributes)
"Like `copy-file' for Tramp files (compat function)."
(cond
(preserve-extended-attributes
@@ -320,21 +139,13 @@ Not actually used. Use `(format \"%o\" i)' instead?"
'copy-file filename newname ok-if-already-exists keep-date
preserve-uid-gid preserve-extended-attributes)
(wrong-number-of-arguments
- (tramp-compat-copy-file
+ (copy-file
filename newname ok-if-already-exists keep-date preserve-uid-gid))))
- (preserve-uid-gid
- (condition-case nil
- (tramp-compat-funcall
- 'copy-file filename newname ok-if-already-exists keep-date
- preserve-uid-gid)
- (wrong-number-of-arguments
- (tramp-compat-copy-file
- filename newname ok-if-already-exists keep-date))))
(t
- (copy-file filename newname ok-if-already-exists keep-date))))
+ (copy-file
+ filename newname ok-if-already-exists keep-date preserve-uid-gid))))
-;; `copy-directory' is a new function in Emacs 23.2. Implementation
-;; is taken from there.
+;; COPY-CONTENTS has been introduced with Emacs 24.1.
(defun tramp-compat-copy-directory
(directory newname &optional keep-time parents copy-contents)
"Make a copy of DIRECTORY (compat function)."
@@ -372,8 +183,7 @@ Not actually used. Use `(format \"%o\" i)' instead?"
(tramp-compat-copy-directory file newname keep-time parents)
(copy-file file newname t keep-time)))
;; We do not want to delete "." and "..".
- (directory-files
- directory 'full "^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*"))
+ (directory-files directory 'full directory-files-no-dot-files-regexp))
;; Set directory attributes.
(set-file-modes newname (file-modes directory))
@@ -401,59 +211,21 @@ Not actually used. Use `(format \"%o\" i)' instead?"
(cond
(trash
(tramp-compat-funcall 'delete-directory directory recursive trash))
- (recursive
- (tramp-compat-funcall 'delete-directory directory recursive))
(t
- (delete-directory directory)))
- ;; This Emacs version does not support the RECURSIVE or TRASH flag. We
- ;; use the implementation from Emacs 23.2.
+ (delete-directory directory recursive)))
+ ;; This Emacs version does not support the TRASH flag. We use the
+ ;; implementation from Emacs 23.2.
(wrong-number-of-arguments
(setq directory (directory-file-name (expand-file-name directory)))
- (if (not (file-symlink-p directory))
- (mapc (lambda (file)
- (if (eq t (car (file-attributes file)))
- (tramp-compat-delete-directory file recursive trash)
- (tramp-compat-delete-file file trash)))
- (directory-files
- directory 'full "^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*")))
+ (when (not (file-symlink-p directory))
+ (mapc (lambda (file)
+ (if (eq t (car (file-attributes file)))
+ (tramp-compat-delete-directory file recursive trash)
+ (tramp-compat-delete-file file trash)))
+ (directory-files
+ directory 'full directory-files-no-dot-files-regexp)))
(delete-directory directory))))
-;; MUST-SUFFIX doesn't exist on XEmacs.
-(defun tramp-compat-load (file &optional noerror nomessage nosuffix must-suffix)
- "Like `load' for Tramp files (compat function)."
- (if must-suffix
- (tramp-compat-funcall 'load file noerror nomessage nosuffix must-suffix)
- (load file noerror nomessage nosuffix)))
-
-;; `number-sequence' does not exist in XEmacs. Implementation is
-;; taken from Emacs 23.
-(defun tramp-compat-number-sequence (from &optional to inc)
- "Return a sequence of numbers from FROM to TO as a list (compat function)."
- (if (or (subrp 'number-sequence) (symbol-file 'number-sequence))
- (tramp-compat-funcall 'number-sequence from to inc)
- (if (or (not to) (= from to))
- (list from)
- (or inc (setq inc 1))
- (when (zerop inc) (error "The increment can not be zero"))
- (let (seq (n 0) (next from))
- (if (> inc 0)
- (while (<= next to)
- (setq seq (cons next seq)
- n (1+ n)
- next (+ from (* n inc))))
- (while (>= next to)
- (setq seq (cons next seq)
- n (1+ n)
- next (+ from (* n inc)))))
- (nreverse seq)))))
-
-(defun tramp-compat-split-string (string pattern)
- "Like `split-string' but omit empty strings.
-In Emacs, (split-string \"/foo/bar\" \"/\") returns (\"foo\" \"bar\").
-This is, the first, empty, element is omitted. In XEmacs, the first
-element is not omitted."
- (delete "" (split-string string pattern)))
-
(defun tramp-compat-process-running-p (process-name)
"Returns t if system process PROCESS-NAME is running for `user-login-name'."
(when (stringp process-name)
@@ -466,7 +238,7 @@ element is not omitted."
((and (fboundp 'list-system-processes) (fboundp 'process-attributes))
(let (result)
(dolist (pid (tramp-compat-funcall 'list-system-processes) result)
- (let ((attributes (tramp-compat-funcall 'process-attributes pid)))
+ (let ((attributes (process-attributes pid)))
(when (and (string-equal
(cdr (assoc 'user attributes)) (user-login-name))
(let ((comm (cdr (assoc 'comm attributes))))
@@ -476,140 +248,137 @@ element is not omitted."
(and comm (string-match
(concat "^" (regexp-quote comm))
process-name))))
- (setq result t))))))
-
- ;; Fallback, if there is no Lisp support yet.
- (t (let ((default-directory
- (if (tramp-tramp-file-p default-directory)
- (tramp-compat-temporary-file-directory)
- default-directory))
- (unix95 (getenv "UNIX95"))
- result)
- (setenv "UNIX95" "1")
- (when (member
- (user-login-name)
- (tramp-compat-split-string
- (shell-command-to-string
- (format "ps -C %s -o user=" process-name))
- "[ \f\t\n\r\v]+"))
- (setq result t))
- (setenv "UNIX95" unix95)
- result)))))
-
-;; The following functions do not exist in XEmacs. We ignore this;
-;; they are used for checking a remote tty.
-(defun tramp-compat-process-get (process propname)
- "Return the value of PROCESS' PROPNAME property.
-This is the last value stored with `(process-put PROCESS PROPNAME VALUE)'."
- (ignore-errors (tramp-compat-funcall 'process-get process propname)))
-
-(defun tramp-compat-process-put (process propname value)
- "Change PROCESS' PROPNAME property to VALUE.
-It can be retrieved with `(process-get PROCESS PROPNAME)'."
- (ignore-errors (tramp-compat-funcall 'process-put process propname value)))
-
-(defun tramp-compat-set-process-query-on-exit-flag (process flag)
- "Specify if query is needed for process when Emacs is exited.
-If the second argument flag is non-nil, Emacs will query the user before
-exiting if process is running."
- (if (fboundp 'set-process-query-on-exit-flag)
- (tramp-compat-funcall 'set-process-query-on-exit-flag process flag)
- (tramp-compat-funcall 'process-kill-without-query process flag)))
-
-;; There exist different implementations for this function.
-(defun tramp-compat-coding-system-change-eol-conversion (coding-system eol-type)
- "Return a coding system like CODING-SYSTEM but with given EOL-TYPE.
-EOL-TYPE can be one of `dos', `unix', or `mac'."
- (cond ((fboundp 'coding-system-change-eol-conversion)
- (tramp-compat-funcall
- 'coding-system-change-eol-conversion coding-system eol-type))
- ((fboundp 'subsidiary-coding-system)
- (tramp-compat-funcall
- 'subsidiary-coding-system coding-system
- (cond ((eq eol-type 'dos) 'crlf)
- ((eq eol-type 'unix) 'lf)
- ((eq eol-type 'mac) 'cr)
- (t (error
- "Unknown EOL-TYPE `%s', must be `dos', `unix', or `mac'"
- eol-type)))))
- (t (error "Can't change EOL conversion -- is MULE missing?"))))
-
-;; `replace-regexp-in-string' does not exist in XEmacs.
-;; Implementation is taken from Emacs 24.
-(if (fboundp 'replace-regexp-in-string)
- (defalias 'tramp-compat-replace-regexp-in-string 'replace-regexp-in-string)
- (defun tramp-compat-replace-regexp-in-string
- (regexp rep string &optional fixedcase literal subexp start)
- "Replace all matches for REGEXP with REP in STRING.
-
-Return a new string containing the replacements.
-
-Optional arguments FIXEDCASE, LITERAL and SUBEXP are like the
-arguments with the same names of function `replace-match'. If START
-is non-nil, start replacements at that index in STRING.
-
-REP is either a string used as the NEWTEXT arg of `replace-match' or a
-function. If it is a function, it is called with the actual text of each
-match, and its value is used as the replacement text. When REP is called,
-the match data are the result of matching REGEXP against a substring
-of STRING.
-
-To replace only the first match (if any), make REGEXP match up to \\'
-and replace a sub-expression, e.g.
- (replace-regexp-in-string \"\\\\(foo\\\\).*\\\\'\" \"bar\" \" foo foo\" nil nil 1)
- => \" bar foo\""
-
- (let ((l (length string))
- (start (or start 0))
- matches str mb me)
- (save-match-data
- (while (and (< start l) (string-match regexp string start))
- (setq mb (match-beginning 0)
- me (match-end 0))
- ;; If we matched the empty string, make sure we advance by one char
- (when (= me mb) (setq me (min l (1+ mb))))
- ;; Generate a replacement for the matched substring.
- ;; Operate only on the substring to minimize string consing.
- ;; Set up match data for the substring for replacement;
- ;; presumably this is likely to be faster than munging the
- ;; match data directly in Lisp.
- (string-match regexp (setq str (substring string mb me)))
- (setq matches
- (cons (replace-match (if (stringp rep)
- rep
- (funcall rep (match-string 0 str)))
- fixedcase literal str subexp)
- (cons (substring string start mb) ; unmatched prefix
- matches)))
- (setq start me))
- ;; Reconstruct a string from the pieces.
- (setq matches (cons (substring string start l) matches)) ; leftover
- (apply #'concat (nreverse matches))))))
+ (setq result t)))))))))
+
+;; `process-running-live-p' is introduced in Emacs 24.
+(defalias 'tramp-compat-process-live-p
+ (if (fboundp 'process-running-live-p)
+ 'process-running-live-p
+ (lambda (process)
+ "Returns non-nil if PROCESS is alive.
+A process is considered alive if its status is `run', `open',
+`listen', `connect' or `stop'. Value is nil if PROCESS is not a
+process."
+ (and (processp process)
+ (memq (process-status process)
+ '(run open listen connect stop))))))
+
+;; `user-error' has appeared in Emacs 24.3.
+(defsubst tramp-compat-user-error (vec-or-proc format &rest args)
+ "Signal a pilot error."
+ (apply
+ 'tramp-error vec-or-proc
+ (if (fboundp 'user-error) 'user-error 'error) format args))
+
+;; `file-attribute-*' are introduced in Emacs 25.1.
+
+(if (fboundp 'file-attribute-type)
+ (defalias 'tramp-compat-file-attribute-type 'file-attribute-type)
+ (defsubst tramp-compat-file-attribute-type (attributes)
+ "The type field in ATTRIBUTES returned by `file-attributes'.
+The value is either t for directory, string (name linked to) for
+symbolic link, or nil."
+ (nth 0 attributes)))
+
+(if (fboundp 'file-attribute-link-number)
+ (defalias 'tramp-compat-file-attribute-link-number
+ 'file-attribute-link-number)
+ (defsubst tramp-compat-file-attribute-link-number (attributes)
+ "Return the number of links in ATTRIBUTES returned by `file-attributes'."
+ (nth 1 attributes)))
+
+(if (fboundp 'file-attribute-user-id)
+ (defalias 'tramp-compat-file-attribute-user-id 'file-attribute-user-id)
+ (defsubst tramp-compat-file-attribute-user-id (attributes)
+ "The UID field in ATTRIBUTES returned by `file-attributes'.
+This is either a string or a number. If a string value cannot be
+looked up, a numeric value, either an integer or a float, is
+returned."
+ (nth 2 attributes)))
+
+(if (fboundp 'file-attribute-group-id)
+ (defalias 'tramp-compat-file-attribute-group-id 'file-attribute-group-id)
+ (defsubst tramp-compat-file-attribute-group-id (attributes)
+ "The GID field in ATTRIBUTES returned by `file-attributes'.
+This is either a string or a number. If a string value cannot be
+looked up, a numeric value, either an integer or a float, is
+returned."
+ (nth 3 attributes)))
+
+(if (fboundp 'file-attribute-modification-time)
+ (defalias 'tramp-compat-file-attribute-modification-time
+ 'file-attribute-modification-time)
+ (defsubst tramp-compat-file-attribute-modification-time (attributes)
+ "The modification time in ATTRIBUTES returned by `file-attributes'.
+This is the time of the last change to the file's contents, and
+is a list of integers (HIGH LOW USEC PSEC) in the same style
+as (current-time)."
+ (nth 5 attributes)))
+
+(if (fboundp 'file-attribute-size)
+ (defalias 'tramp-compat-file-attribute-size 'file-attribute-size)
+ (defsubst tramp-compat-file-attribute-size (attributes)
+ "The size (in bytes) in ATTRIBUTES returned by `file-attributes'.
+This is a floating point number if the size is too large for an integer."
+ (nth 7 attributes)))
+
+(if (fboundp 'file-attribute-modes)
+ (defalias 'tramp-compat-file-attribute-modes 'file-attribute-modes)
+ (defsubst tramp-compat-file-attribute-modes (attributes)
+ "The file modes in ATTRIBUTES returned by `file-attributes'.
+This is a string of ten letters or dashes as in ls -l."
+ (nth 8 attributes)))
;; `default-toplevel-value' has been declared in Emacs 24.
(unless (fboundp 'default-toplevel-value)
(defalias 'default-toplevel-value 'symbol-value))
-;; `format-message' is new in Emacs 25, and does not exist in XEmacs.
+;; `format-message' is new in Emacs 25.
(unless (fboundp 'format-message)
(defalias 'format-message 'format))
-;; `delete-dups' does not exist in XEmacs 21.4.
-(if (fboundp 'delete-dups)
- (defalias 'tramp-compat-delete-dups 'delete-dups)
- (defun tramp-compat-delete-dups (list)
- "Destructively remove `equal' duplicates from LIST.
-Store the result in LIST and return it. LIST must be a proper list.
-Of several `equal' occurrences of an element in LIST, the first
-one is kept."
- (tramp-compat-funcall
- 'cl-delete-duplicates list '(:test equal :from-end) nil)))
+;; `file-missing' is introduced in Emacs 26.
+(defconst tramp-file-missing
+ (if (get 'file-missing 'error-conditions) 'file-missing 'file-error)
+ "The error symbol for the `file-missing' error.")
(add-hook 'tramp-unload-hook
(lambda ()
(unload-feature 'tramp-loaddefs 'force)
(unload-feature 'tramp-compat 'force)))
+;; `file-name-quoted-p', `file-name-quote' and `file-name-unquote' are
+;; introduced in Emacs 26.
+(eval-and-compile
+ (if (fboundp 'file-name-quoted-p)
+ (defalias 'tramp-compat-file-name-quoted-p 'file-name-quoted-p)
+ (defsubst tramp-compat-file-name-quoted-p (name)
+ "Whether NAME is quoted with prefix \"/:\".
+If NAME is a remote file name, check the local part of NAME."
+ (string-match "^/:" (or (file-remote-p name 'localname) name))))
+
+ (if (fboundp 'file-name-quote)
+ (defalias 'tramp-compat-file-name-quote 'file-name-quote)
+ (defsubst tramp-compat-file-name-quote (name)
+ "Add the quotation prefix \"/:\" to file NAME.
+If NAME is a remote file name, the local part of NAME is quoted."
+ (concat
+ (file-remote-p name) "/:" (or (file-remote-p name 'localname) name))))
+
+ (if (fboundp 'file-name-unquote)
+ (defalias 'tramp-compat-file-name-unquote 'file-name-unquote)
+ (defsubst tramp-compat-file-name-unquote (name)
+ "Remove quotation prefix \"/:\" from file NAME.
+If NAME is a remote file name, the local part of NAME is unquoted."
+ (save-match-data
+ (let ((localname (or (file-remote-p name 'localname) name)))
+ (when (tramp-compat-file-name-quoted-p localname)
+ (setq
+ localname
+ (replace-match
+ (if (= (length localname) 2) "/" "") nil t localname)))
+ (concat (file-remote-p name) localname))))))
+
(provide 'tramp-compat)
;;; TODO:
diff --git a/lisp/net/tramp-ftp.el b/lisp/net/tramp-ftp.el
index 902b0a4ed86..20a12eb6936 100644
--- a/lisp/net/tramp-ftp.el
+++ b/lisp/net/tramp-ftp.el
@@ -39,15 +39,6 @@
(defvar ange-ftp-name-format)
;; Disable Ange-FTP from file-name-handler-alist.
-;; To handle EFS, the following functions need to be dealt with:
-;;
-;; * dired-before-readin-hook contains efs-dired-before-readin
-;; * file-name-handler-alist contains efs-file-handler-function
-;; and efs-root-handler-function and efs-sifn-handler-function
-;; * find-file-hooks contains efs-set-buffer-mode
-;;
-;; But it won't happen for EFS since the XEmacs maintainers
-;; don't want to use a unified filename syntax.
(defun tramp-disable-ange-ftp ()
"Turn Ange-FTP off.
This is useful for unified remoting. See
@@ -69,6 +60,7 @@ present for backward compatibility."
;;;###autoload
(defun tramp-ftp-enable-ange-ftp ()
+ "Reenable Ange-FTP, when Tramp is unloaded."
;; The following code is commented out in Ange-FTP.
;;; This regexp takes care of real ange-ftp file names (with a slash
@@ -104,14 +96,15 @@ present for backward compatibility."
;; ... and add it to the method list.
;;;###tramp-autoload
-(unless (featurep 'xemacs)
- (add-to-list 'tramp-methods (cons tramp-ftp-method nil))
+(add-to-list 'tramp-methods (cons tramp-ftp-method nil))
- ;; Add some defaults for `tramp-default-method-alist'.
- (add-to-list 'tramp-default-method-alist
- (list "\\`ftp\\." nil tramp-ftp-method))
- (add-to-list 'tramp-default-method-alist
- (list nil "\\`\\(anonymous\\|ftp\\)\\'" tramp-ftp-method)))
+;; Add some defaults for `tramp-default-method-alist'.
+;;;###tramp-autoload
+(add-to-list 'tramp-default-method-alist
+ (list "\\`ftp\\." nil tramp-ftp-method))
+;;;###tramp-autoload
+(add-to-list 'tramp-default-method-alist
+ (list nil "\\`\\(anonymous\\|ftp\\)\\'" tramp-ftp-method))
;; Add completion function for FTP method.
;;;###tramp-autoload
@@ -195,9 +188,8 @@ pass to the OPERATION."
tramp-ftp-method))
;;;###tramp-autoload
-(unless (featurep 'xemacs)
- (add-to-list 'tramp-foreign-file-name-handler-alist
- (cons 'tramp-ftp-file-name-p 'tramp-ftp-file-name-handler)))
+(add-to-list 'tramp-foreign-file-name-handler-alist
+ (cons 'tramp-ftp-file-name-p 'tramp-ftp-file-name-handler))
(add-hook 'tramp-unload-hook
(lambda ()
diff --git a/lisp/net/tramp-gvfs.el b/lisp/net/tramp-gvfs.el
index dee8333e547..37aba59e12e 100644
--- a/lisp/net/tramp-gvfs.el
+++ b/lisp/net/tramp-gvfs.el
@@ -49,10 +49,10 @@
;; The custom option `tramp-gvfs-methods' contains the list of
;; supported connection methods. Per default, these are "afp", "dav",
-;; "davs", "obex", "sftp" and "synce". Note that with "obex" it might
-;; be necessary to pair with the other bluetooth device, if it hasn't
-;; been done already. There might be also some few seconds delay in
-;; discovering available bluetooth devices.
+;; "davs", "gdrive", "obex", "sftp" and "synce". Note that with
+;; "obex" it might be necessary to pair with the other bluetooth
+;; device, if it hasn't been done already. There might be also some
+;; few seconds delay in discovering available bluetooth devices.
;; Other possible connection methods are "ftp" and "smb". When one of
;; these methods is added to the list, the remote access for that
@@ -110,21 +110,30 @@
(require 'custom))
;;;###tramp-autoload
-(defcustom tramp-gvfs-methods '("afp" "dav" "davs" "obex" "sftp" "synce")
+(defcustom tramp-gvfs-methods
+ '("afp" "dav" "davs" "gdrive" "obex" "sftp" "synce")
"List of methods for remote files, accessed with GVFS."
:group 'tramp
- :version "25.1"
+ :version "26.1"
:type '(repeat (choice (const "afp")
(const "dav")
(const "davs")
(const "ftp")
+ (const "gdrive")
(const "obex")
(const "sftp")
(const "smb")
- (const "synce"))))
+ (const "synce")))
+ :require 'tramp)
-;; Add a default for `tramp-default-user-alist'. Rule: For the SYNCE
-;; method, no user is chosen.
+;; Add defaults for `tramp-default-user-alist' and `tramp-default-host-alist'.
+;;;###tramp-autoload
+(when (string-match "\\(.+\\)@\\(\\(?:gmail\\|googlemail\\)\\.com\\)"
+ user-mail-address)
+ (add-to-list 'tramp-default-user-alist
+ `("\\`gdrive\\'" nil ,(match-string 1 user-mail-address)))
+ (add-to-list 'tramp-default-host-alist
+ '("\\`gdrive\\'" nil ,(match-string 2 user-mail-address))))
;;;###tramp-autoload
(add-to-list 'tramp-default-user-alist '("\\`synce\\'" nil nil))
@@ -133,7 +142,8 @@
"Zeroconf domain to be used for discovering services, like host names."
:group 'tramp
:version "23.2"
- :type 'string)
+ :type 'string
+ :require 'tramp)
;; Add the methods to `tramp-methods', in order to allow minibuffer
;; completion.
@@ -385,7 +395,8 @@ completion, nil means to use always cached values for discovered
devices."
:group 'tramp
:version "23.2"
- :type '(choice (const nil) integer))
+ :type '(choice (const nil) integer)
+ :require 'tramp)
(defvar tramp-bluez-discovery nil
"Indicator for a running bluetooth device discovery.
@@ -407,6 +418,38 @@ Every entry is a list (NAME ADDRESS).")
(defconst tramp-hal-interface-device "org.freedesktop.Hal.Device"
"The device interface of the HAL daemon.")
+(defconst tramp-gvfs-file-attributes
+ '("name"
+ "type"
+ "standard::display-name"
+ "standard::symlink-target"
+ "unix::nlink"
+ "unix::uid"
+ "owner::user"
+ "unix::gid"
+ "owner::group"
+ "time::access"
+ "time::modified"
+ "time::changed"
+ "standard::size"
+ "unix::mode"
+ "access::can-read"
+ "access::can-write"
+ "access::can-execute"
+ "unix::inode"
+ "unix::device")
+ "GVFS file attributes.")
+
+(defconst tramp-gvfs-file-attributes-with-gvfs-ls-regexp
+ (concat "[[:blank:]]" (regexp-opt tramp-gvfs-file-attributes t) "=\\(.+?\\)")
+ "Regexp to parse GVFS file attributes with `gvfs-ls'.")
+
+(defconst tramp-gvfs-file-attributes-with-gvfs-info-regexp
+ (concat "^[[:blank:]]*"
+ (regexp-opt tramp-gvfs-file-attributes t)
+ ":[[:blank:]]+\\(.*\\)$")
+ "Regexp to parse GVFS file attributes with `gvfs-info'.")
+
;; New handlers should be added here.
(defconst tramp-gvfs-file-name-handler-alist
@@ -422,7 +465,6 @@ Every entry is a list (NAME ADDRESS).")
(directory-files . tramp-handle-directory-files)
(directory-files-and-attributes
. tramp-handle-directory-files-and-attributes)
- (dired-call-process . ignore)
(dired-compress-file . ignore)
(dired-uncache . tramp-handle-dired-uncache)
(expand-file-name . tramp-gvfs-handle-expand-file-name)
@@ -438,6 +480,7 @@ Every entry is a list (NAME ADDRESS).")
(file-modes . tramp-handle-file-modes)
(file-name-all-completions . tramp-gvfs-handle-file-name-all-completions)
(file-name-as-directory . tramp-handle-file-name-as-directory)
+ (file-name-case-insensitive-p . tramp-handle-file-name-case-insensitive-p)
(file-name-completion . tramp-handle-file-name-completion)
(file-name-directory . tramp-handle-file-name-directory)
(file-name-nondirectory . tramp-handle-file-name-nondirectory)
@@ -463,6 +506,7 @@ Every entry is a list (NAME ADDRESS).")
(make-auto-save-file-name . tramp-handle-make-auto-save-file-name)
(make-directory . tramp-gvfs-handle-make-directory)
(make-directory-internal . ignore)
+ (make-nearby-temp-file . tramp-handle-make-nearby-temp-file)
(make-symbolic-link . tramp-handle-make-symbolic-link)
(process-file . ignore)
(rename-file . tramp-gvfs-handle-rename-file)
@@ -474,7 +518,8 @@ Every entry is a list (NAME ADDRESS).")
(shell-command . ignore)
(start-file-process . ignore)
(substitute-in-file-name . tramp-handle-substitute-in-file-name)
- (unhandled-file-name-directory . tramp-handle-unhandled-file-name-directory)
+ (temporary-file-directory . tramp-handle-temporary-file-directory)
+ (unhandled-file-name-directory . ignore)
(vc-registered . ignore)
(verify-visited-file-modtime . tramp-handle-verify-visited-file-modtime)
(write-region . tramp-gvfs-handle-write-region))
@@ -497,7 +542,7 @@ Operations not mentioned here will be handled by the default Emacs primitives.")
First arg specifies the OPERATION, second arg is a list of arguments to
pass to the OPERATION."
(unless tramp-gvfs-enabled
- (tramp-user-error nil "Package `tramp-gvfs' not supported"))
+ (tramp-compat-user-error nil "Package `tramp-gvfs' not supported"))
(let ((fn (assoc operation tramp-gvfs-file-name-handler-alist)))
(if fn
(save-match-data (apply (cdr fn) args))
@@ -562,8 +607,7 @@ will be traced by Tramp with trace level 6."
(put 'with-tramp-dbus-call-method 'lisp-indent-function 2)
(put 'with-tramp-dbus-call-method 'edebug-form-spec '(form symbolp body))
-(tramp-compat-font-lock-add-keywords
- 'emacs-lisp-mode '("\\<with-tramp-dbus-call-method\\>"))
+(font-lock-add-keywords 'emacs-lisp-mode '("\\<with-tramp-dbus-call-method\\>"))
(defvar tramp-gvfs-dbus-event-vector nil
"Current Tramp file name to be used, as vector.
@@ -587,7 +631,7 @@ is no information where to trace the message.")
(defun tramp-gvfs-do-copy-or-rename-file
(op filename newname &optional ok-if-already-exists keep-date
- preserve-uid-gid preserve-extended-attributes)
+ preserve-uid-gid preserve-extended-attributes)
"Copy or rename a remote file.
OP must be `copy' or `rename' and indicates the operation to perform.
FILENAME specifies the file to copy or rename, NEWNAME is the name of
@@ -623,19 +667,19 @@ file names."
(and t2 (not (tramp-gvfs-file-name-p newname))))
;; We cannot copy or rename directly.
+ ;; PRESERVE-EXTENDED-ATTRIBUTES has been introduced with
+ ;; Emacs 24.1 (as PRESERVE-SELINUX-CONTEXT), and renamed
+ ;; in Emacs 24.3.
(let ((tmpfile (tramp-compat-make-temp-file filename)))
(cond
(preserve-extended-attributes
- (tramp-compat-funcall
+ (funcall
file-operation
filename tmpfile t keep-date preserve-uid-gid
preserve-extended-attributes))
- (preserve-uid-gid
- (tramp-compat-funcall
- file-operation filename tmpfile t keep-date preserve-uid-gid))
(t
- (tramp-compat-funcall
- file-operation filename tmpfile t keep-date)))
+ (funcall
+ file-operation filename tmpfile t keep-date preserve-uid-gid)))
(rename-file tmpfile newname ok-if-already-exists))
;; Direct action.
@@ -646,7 +690,7 @@ file names."
'tramp-gvfs-send-command v gvfs-operation
(append
(and (eq op 'copy) (or keep-date preserve-uid-gid)
- (list "--preserve"))
+ '("--preserve"))
(list
(tramp-gvfs-url-file-name filename)
(tramp-gvfs-url-file-name newname))))
@@ -682,7 +726,7 @@ file names."
(defun tramp-gvfs-handle-copy-file
(filename newname &optional ok-if-already-exists keep-date
- preserve-uid-gid preserve-extended-attributes)
+ preserve-uid-gid preserve-extended-attributes)
"Like `copy-file' for Tramp files."
(setq filename (expand-file-name filename))
(setq newname (expand-file-name newname))
@@ -693,30 +737,34 @@ file names."
(tramp-gvfs-do-copy-or-rename-file
'copy filename newname ok-if-already-exists keep-date
preserve-uid-gid preserve-extended-attributes))
- ;; Compat section.
+ ;; Compat section. PRESERVE-EXTENDED-ATTRIBUTES has been
+ ;; introduced with Emacs 24.1 (as PRESERVE-SELINUX-CONTEXT), and
+ ;; renamed in Emacs 24.3.
(preserve-extended-attributes
(tramp-run-real-handler
'copy-file
(list filename newname ok-if-already-exists keep-date
preserve-uid-gid preserve-extended-attributes)))
- (preserve-uid-gid
- (tramp-run-real-handler
- 'copy-file
- (list filename newname ok-if-already-exists keep-date preserve-uid-gid)))
(t
(tramp-run-real-handler
- 'copy-file (list filename newname ok-if-already-exists keep-date)))))
+ 'copy-file
+ (list filename newname ok-if-already-exists keep-date preserve-uid-gid)))))
(defun tramp-gvfs-handle-delete-directory (directory &optional recursive trash)
"Like `delete-directory' for Tramp files."
- (when (and recursive (not (file-symlink-p directory)))
- (mapc (lambda (file)
- (if (eq t (car (file-attributes file)))
- (tramp-compat-delete-directory file recursive trash)
- (tramp-compat-delete-file file trash)))
- (directory-files
- directory 'full "^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*")))
(with-parsed-tramp-file-name directory nil
+ (if (and recursive (not (file-symlink-p directory)))
+ (mapc (lambda (file)
+ (if (eq t (tramp-compat-file-attribute-type
+ (file-attributes file)))
+ (tramp-compat-delete-directory file recursive trash)
+ (tramp-compat-delete-file file trash)))
+ (directory-files
+ directory 'full directory-files-no-dot-files-regexp))
+ (when (directory-files directory nil directory-files-no-dot-files-regexp)
+ (tramp-error
+ v 'file-error "Couldn't delete non-empty %s" directory)))
+
(tramp-flush-file-property v (file-name-directory localname))
(tramp-flush-directory-property v localname)
(unless
@@ -762,7 +810,7 @@ file names."
(tramp-gvfs-maybe-open-connection (vector method user host "/" hop)))
(setq localname
(replace-match
- (tramp-get-file-property v "/" "default-location" "~")
+ (tramp-get-connection-property v "default-location" "~")
nil t localname 1)))
;; Tilde expansion is not possible.
(when (string-match "\\`\\(~[^/]*\\)\\(.*\\)\\'" localname)
@@ -787,127 +835,193 @@ file names."
(tramp-run-real-handler
'expand-file-name (list localname))))))
-(defun tramp-gvfs-handle-file-attributes (filename &optional id-format)
- "Like `file-attributes' for Tramp files."
- (unless id-format (setq id-format 'integer))
+(defun tramp-gvfs-get-directory-attributes (directory)
+ "Return GVFS attributes association list of all files in DIRECTORY."
(ignore-errors
;; Don't modify `last-coding-system-used' by accident.
(let ((last-coding-system-used last-coding-system-used)
- (process-environment (cons "LC_MESSAGES=C" process-environment))
- dirp res-symlink-target res-numlinks res-uid res-gid res-access
- res-mod res-change res-size res-filemodes res-inode res-device)
+ result)
+ (with-parsed-tramp-file-name directory nil
+ (with-tramp-file-property v localname "directory-gvfs-attributes"
+ (tramp-message v 5 "directory gvfs attributes: %s" localname)
+ ;; Send command.
+ (tramp-gvfs-send-command
+ v "gvfs-ls" "-h" "-n" "-a"
+ (mapconcat 'identity tramp-gvfs-file-attributes ",")
+ (tramp-gvfs-url-file-name directory))
+ ;; Parse output.
+ (with-current-buffer (tramp-get-connection-buffer v)
+ (goto-char (point-min))
+ (while (looking-at
+ (concat "^\\(.+\\)[[:blank:]]"
+ "\\([[:digit:]]+\\)[[:blank:]]"
+ "(\\(.+?\\))"
+ tramp-gvfs-file-attributes-with-gvfs-ls-regexp))
+ (let ((item (list (cons "type" (match-string 3))
+ (cons "standard::size" (match-string 2))
+ (cons "name" (match-string 1)))))
+ (goto-char (1+ (match-end 3)))
+ (while (looking-at
+ (concat
+ tramp-gvfs-file-attributes-with-gvfs-ls-regexp
+ "\\(" tramp-gvfs-file-attributes-with-gvfs-ls-regexp
+ "\\|" "$" "\\)"))
+ (push (cons (match-string 1) (match-string 2)) item)
+ (goto-char (match-end 2)))
+ ;; Add display name as head.
+ (push
+ (cons (cdr (or (assoc "standard::display-name" item)
+ (assoc "name" item)))
+ (nreverse item))
+ result))
+ (forward-line)))
+ result)))))
+
+(defun tramp-gvfs-get-root-attributes (filename)
+ "Return GVFS attributes association list of FILENAME."
+ (ignore-errors
+ ;; Don't modify `last-coding-system-used' by accident.
+ (let ((last-coding-system-used last-coding-system-used)
+ result)
(with-parsed-tramp-file-name filename nil
- (with-tramp-file-property
- v localname (format "file-attributes-%s" id-format)
- (tramp-message v 5 "file attributes: %s" localname)
+ (with-tramp-file-property v localname "file-gvfs-attributes"
+ (tramp-message v 5 "file gvfs attributes: %s" localname)
+ ;; Send command.
(tramp-gvfs-send-command
v "gvfs-info" (tramp-gvfs-url-file-name filename))
- ;; Parse output ...
+ ;; Parse output.
(with-current-buffer (tramp-get-connection-buffer v)
(goto-char (point-min))
- (when (re-search-forward "attributes:" nil t)
- ;; ... directory or symlink
- (goto-char (point-min))
- (setq dirp (if (re-search-forward "type: directory" nil t) t))
- (goto-char (point-min))
- (setq res-symlink-target
- (if (re-search-forward
- "standard::symlink-target: \\(.+\\)$" nil t)
- (match-string 1)))
- ;; ... number links
- (goto-char (point-min))
- (setq res-numlinks
- (if (re-search-forward "unix::nlink: \\([0-9]+\\)" nil t)
- (string-to-number (match-string 1)) 0))
- ;; ... uid and gid
- (goto-char (point-min))
- (setq res-uid
- (if (eq id-format 'integer)
- (if (re-search-forward "unix::uid: \\([0-9]+\\)" nil t)
- (string-to-number (match-string 1))
- -1)
- (if (re-search-forward "owner::user: \\(.+\\)$" nil t)
- (match-string 1)
- "UNKNOWN")))
- (setq res-gid
- (if (eq id-format 'integer)
- (if (re-search-forward "unix::gid: \\([0-9]+\\)" nil t)
- (string-to-number (match-string 1))
- -1)
- (if (re-search-forward "owner::group: \\(.+\\)$" nil t)
- (match-string 1)
- "UNKNOWN")))
- ;; ... last access, modification and change time
- (goto-char (point-min))
- (setq res-access
- (if (re-search-forward "time::access: \\([0-9]+\\)" nil t)
- (seconds-to-time (string-to-number (match-string 1)))
- '(0 0)))
- (goto-char (point-min))
- (setq res-mod
- (if (re-search-forward "time::modified: \\([0-9]+\\)" nil t)
- (seconds-to-time (string-to-number (match-string 1)))
- '(0 0)))
- (goto-char (point-min))
- (setq res-change
- (if (re-search-forward "time::changed: \\([0-9]+\\)" nil t)
- (seconds-to-time (string-to-number (match-string 1)))
- '(0 0)))
- ;; ... size
- (goto-char (point-min))
- (setq res-size
- (if (re-search-forward "standard::size: \\([0-9]+\\)" nil t)
- (string-to-number (match-string 1)) 0))
- ;; ... file mode flags
- (goto-char (point-min))
- (setq res-filemodes
- (if (re-search-forward "unix::mode: \\([0-9]+\\)" nil t)
- (tramp-file-mode-from-int
- (string-to-number (match-string 1)))
- (if dirp "drwx------" "-rwx------")))
- ;; ... inode and device
- (goto-char (point-min))
- (setq res-inode
- (if (re-search-forward "unix::inode: \\([0-9]+\\)" nil t)
- (string-to-number (match-string 1))
- (tramp-get-inode v)))
- (goto-char (point-min))
- (setq res-device
- (if (re-search-forward "unix::device: \\([0-9]+\\)" nil t)
- (string-to-number (match-string 1))
- (tramp-get-device v)))
-
- ;; Return data gathered.
- (list
- ;; 0. t for directory, string (name linked to) for
- ;; symbolic link, or nil.
- (or dirp res-symlink-target)
- ;; 1. Number of links to file.
- res-numlinks
- ;; 2. File uid.
- res-uid
- ;; 3. File gid.
- res-gid
- ;; 4. Last access time, as a list of integers.
- ;; 5. Last modification time, likewise.
- ;; 6. Last status change time, likewise.
- res-access res-mod res-change
- ;; 7. Size in bytes (-1, if number is out of range).
- res-size
- ;; 8. File modes.
- res-filemodes
- ;; 9. t if file's gid would change if file were deleted
- ;; and recreated.
- nil
- ;; 10. Inode number.
- res-inode
- ;; 11. Device number.
- res-device
- ))))))))
+ (while (re-search-forward
+ tramp-gvfs-file-attributes-with-gvfs-info-regexp nil t)
+ (push (cons (match-string 1) (match-string 2)) result))
+ result))))))
+
+(defun tramp-gvfs-get-file-attributes (filename)
+ "Return GVFS attributes association list of FILENAME."
+ (setq filename (directory-file-name (expand-file-name filename)))
+ (with-parsed-tramp-file-name filename nil
+ (setq localname (tramp-compat-file-name-unquote localname))
+ (if (or
+ (and (string-match "^\\(afp\\|smb\\)$" method)
+ (string-match "^/?\\([^/]+\\)$" localname))
+ (string-equal localname "/"))
+ (tramp-gvfs-get-root-attributes filename)
+ (assoc
+ (file-name-nondirectory filename)
+ (tramp-gvfs-get-directory-attributes (file-name-directory filename))))))
+
+(defun tramp-gvfs-handle-file-attributes (filename &optional id-format)
+ "Like `file-attributes' for Tramp files."
+ (unless id-format (setq id-format 'integer))
+ (ignore-errors
+ (let ((attributes (tramp-gvfs-get-file-attributes filename))
+ dirp res-symlink-target res-numlinks res-uid res-gid res-access
+ res-mod res-change res-size res-filemodes res-inode res-device)
+ (when attributes
+ ;; ... directory or symlink
+ (setq dirp (if (equal "directory" (cdr (assoc "type" attributes))) t))
+ (setq res-symlink-target
+ (cdr (assoc "standard::symlink-target" attributes)))
+ ;; ... number links
+ (setq res-numlinks
+ (string-to-number
+ (or (cdr (assoc "unix::nlink" attributes)) "0")))
+ ;; ... uid and gid
+ (setq res-uid
+ (if (eq id-format 'integer)
+ (string-to-number
+ (or (cdr (assoc "unix::uid" attributes))
+ (format "%s" tramp-unknown-id-integer)))
+ (or (cdr (assoc "owner::user" attributes))
+ (cdr (assoc "unix::uid" attributes))
+ tramp-unknown-id-string)))
+ (setq res-gid
+ (if (eq id-format 'integer)
+ (string-to-number
+ (or (cdr (assoc "unix::gid" attributes))
+ (format "%s" tramp-unknown-id-integer)))
+ (or (cdr (assoc "owner::group" attributes))
+ (cdr (assoc "unix::gid" attributes))
+ tramp-unknown-id-string)))
+ ;; ... last access, modification and change time
+ (setq res-access
+ (seconds-to-time
+ (string-to-number
+ (or (cdr (assoc "time::access" attributes)) "0"))))
+ (setq res-mod
+ (seconds-to-time
+ (string-to-number
+ (or (cdr (assoc "time::modified" attributes)) "0"))))
+ (setq res-change
+ (seconds-to-time
+ (string-to-number
+ (or (cdr (assoc "time::changed" attributes)) "0"))))
+ ;; ... size
+ (setq res-size
+ (string-to-number
+ (or (cdr (assoc "standard::size" attributes)) "0")))
+ ;; ... file mode flags
+ (setq res-filemodes
+ (let ((n (cdr (assoc "unix::mode" attributes))))
+ (if n
+ (tramp-file-mode-from-int (string-to-number n))
+ (format
+ "%s%s%s%s------"
+ (if dirp "d" "-")
+ (if (equal (cdr (assoc "access::can-read" attributes))
+ "FALSE")
+ "-" "r")
+ (if (equal (cdr (assoc "access::can-write" attributes))
+ "FALSE")
+ "-" "w")
+ (if (equal (cdr (assoc "access::can-execute" attributes))
+ "FALSE")
+ "-" "x")))))
+ ;; ... inode and device
+ (setq res-inode
+ (let ((n (cdr (assoc "unix::inode" attributes))))
+ (if n
+ (string-to-number n)
+ (tramp-get-inode (tramp-dissect-file-name filename)))))
+ (setq res-device
+ (let ((n (cdr (assoc "unix::device" attributes))))
+ (if n
+ (string-to-number n)
+ (tramp-get-device (tramp-dissect-file-name filename)))))
+
+ ;; Return data gathered.
+ (list
+ ;; 0. t for directory, string (name linked to) for
+ ;; symbolic link, or nil.
+ (or dirp res-symlink-target)
+ ;; 1. Number of links to file.
+ res-numlinks
+ ;; 2. File uid.
+ res-uid
+ ;; 3. File gid.
+ res-gid
+ ;; 4. Last access time, as a list of integers.
+ ;; 5. Last modification time, likewise.
+ ;; 6. Last status change time, likewise.
+ res-access res-mod res-change
+ ;; 7. Size in bytes (-1, if number is out of range).
+ res-size
+ ;; 8. File modes.
+ res-filemodes
+ ;; 9. t if file's gid would change if file were deleted
+ ;; and recreated.
+ nil
+ ;; 10. Inode number.
+ res-inode
+ ;; 11. Device number.
+ res-device
+ )))))
(defun tramp-gvfs-handle-file-directory-p (filename)
"Like `file-directory-p' for Tramp files."
- (eq t (car (file-attributes filename))))
+ (eq t (tramp-compat-file-attribute-type
+ (file-attributes (file-truename filename)))))
(defun tramp-gvfs-handle-file-executable-p (filename)
"Like `file-executable-p' for Tramp files."
@@ -921,81 +1035,24 @@ file names."
(let ((tmpfile (tramp-compat-make-temp-file filename)))
(unless (file-exists-p filename)
(tramp-error
- v 'file-error
+ v tramp-file-missing
"Cannot make local copy of non-existing file `%s'" filename))
- (copy-file filename tmpfile t t)
+ (copy-file filename tmpfile 'ok-if-already-exists 'keep-time)
tmpfile)))
(defun tramp-gvfs-handle-file-name-all-completions (filename directory)
"Like `file-name-all-completions' for Tramp files."
(unless (save-match-data (string-match "/" filename))
- (with-parsed-tramp-file-name (expand-file-name directory) nil
-
- (all-completions
- filename
- (mapcar
- 'list
- (or
- ;; Try cache entries for filename, filename with last
- ;; character removed, filename with last two characters
- ;; removed, ..., and finally the empty string - all
- ;; concatenated to the local directory name.
- (let ((remote-file-name-inhibit-cache
- (or remote-file-name-inhibit-cache
- tramp-completion-reread-directory-timeout)))
-
- ;; This is inefficient for very long filenames, pity
- ;; `reduce' is not available...
- (car
- (apply
- 'append
- (mapcar
- (lambda (x)
- (let ((cache-hit
- (tramp-get-file-property
- v
- (concat localname (substring filename 0 x))
- "file-name-all-completions"
- nil)))
- (when cache-hit (list cache-hit))))
- ;; We cannot use a length of 0, because file properties
- ;; for "foo" and "foo/" are identical.
- (tramp-compat-number-sequence (length filename) 1 -1)))))
-
- ;; Cache expired or no matching cache entry found so we need
- ;; to perform a remote operation.
- (let ((result '("." ".."))
- entry)
+ (all-completions
+ filename
+ (with-parsed-tramp-file-name (expand-file-name directory) nil
+ (with-tramp-file-property v localname "file-name-all-completions"
+ (let ((result '("./" "../")))
;; Get a list of directories and files.
- (tramp-gvfs-send-command
- v "gvfs-ls" "-h" (tramp-gvfs-url-file-name directory))
-
- ;; Now grab the output.
- (with-temp-buffer
- (insert-buffer-substring (tramp-get-connection-buffer v))
- (goto-char (point-max))
- (while (zerop (forward-line -1))
- (setq entry (buffer-substring (point) (point-at-eol)))
- (when (string-match filename entry)
- (if (file-directory-p (expand-file-name entry directory))
- (push (concat entry "/") result)
- (push entry result)))))
-
- ;; Because the remote op went through OK we know the
- ;; directory we `cd'-ed to exists.
- (tramp-set-file-property v localname "file-exists-p" t)
-
- ;; Because the remote op went through OK we know every
- ;; file listed by `ls' exists.
- (mapc (lambda (entry)
- (tramp-set-file-property
- v (concat localname entry) "file-exists-p" t))
- result)
-
- ;; Store result in the cache.
- (tramp-set-file-property
- v (concat localname filename)
- "file-name-all-completions" result))))))))
+ (dolist (item (tramp-gvfs-get-directory-attributes directory) result)
+ (if (string-equal (cdr (assoc "type" item)) "directory")
+ (push (file-name-as-directory (car item)) result)
+ (push (car item) result)))))))))
(defun tramp-gvfs-handle-file-notify-add-watch (file-name flags _callback)
"Like `file-notify-add-watch' for Tramp files."
@@ -1024,14 +1081,14 @@ file names."
(tramp-message
v 6 "Run `%s', %S" (mapconcat 'identity (process-command p) " ") p)
(tramp-set-connection-property p "vector" v)
- (tramp-compat-process-put p 'events events)
- (tramp-compat-process-put p 'watch-name localname)
- (tramp-compat-set-process-query-on-exit-flag p nil)
+ (process-put p 'events events)
+ (process-put p 'watch-name localname)
+ (set-process-query-on-exit-flag p nil)
(set-process-filter p 'tramp-gvfs-monitor-file-process-filter)
;; There might be an error if the monitor is not supported.
;; Give the filter a chance to read the output.
(tramp-accept-process-output p 1)
- (unless (memq (process-status p) '(run open))
+ (unless (tramp-compat-process-live-p p)
(tramp-error
v 'file-notify-error "Monitoring not supported for `%s'" file-name))
p))))
@@ -1039,7 +1096,7 @@ file names."
(defun tramp-gvfs-monitor-file-process-filter (proc string)
"Read output from \"gvfs-monitor-file\" and add corresponding \
file-notify events."
- (let* ((rest-string (tramp-compat-process-get proc 'rest-string))
+ (let* ((rest-string (process-get proc 'rest-string))
(dd (with-current-buffer (process-buffer proc) default-directory))
(ddu (regexp-quote (tramp-gvfs-url-file-name dd))))
(when rest-string
@@ -1047,7 +1104,7 @@ file-notify events."
(tramp-message proc 6 "%S\n%s" proc string)
(setq string (concat rest-string string)
;; Attribute change is returned in unused wording.
- string (tramp-compat-replace-regexp-in-string
+ string (replace-regexp-in-string
"ATTRIB CHANGED" "ATTRIBUTE_CHANGED" string))
(when (string-match "Monitoring not supported" string)
(delete-process proc))
@@ -1060,7 +1117,7 @@ file-notify events."
string)
(let ((file (match-string 1 string))
(action (intern-soft
- (tramp-compat-replace-regexp-in-string
+ (replace-regexp-in-string
"_" "-" (downcase (match-string 2 string))))))
(setq string (replace-match "" nil nil string))
;; File names are returned as URL paths. We must convert them.
@@ -1079,12 +1136,12 @@ file-notify events."
;; Save rest of the string.
(when (zerop (length string)) (setq string nil))
(when string (tramp-message proc 10 "Rest string:\n%s" string))
- (tramp-compat-process-put proc 'rest-string string)))
+ (process-put proc 'rest-string string)))
(defun tramp-gvfs-handle-file-readable-p (filename)
"Like `file-readable-p' for Tramp files."
(with-parsed-tramp-file-name filename nil
- (with-tramp-file-property v localname "file-executable-p"
+ (with-tramp-file-property v localname "file-readable-p"
(tramp-check-cached-permissions v ?r))))
(defun tramp-gvfs-handle-file-writable-p (filename)
@@ -1125,7 +1182,8 @@ file-notify events."
(if (or (tramp-tramp-file-p filename)
(tramp-tramp-file-p newname))
(tramp-gvfs-do-copy-or-rename-file
- 'rename filename newname ok-if-already-exists t t)
+ 'rename filename newname ok-if-already-exists
+ 'keep-date 'preserve-uid-gid)
(tramp-run-real-handler
'rename-file (list filename newname ok-if-already-exists))))
@@ -1133,8 +1191,7 @@ file-notify events."
(start end filename &optional append visit lockname confirm)
"Like `write-region' for Tramp files."
(with-parsed-tramp-file-name filename nil
- ;; XEmacs takes a coding system as the seventh argument, not `confirm'.
- (when (and (not (featurep 'xemacs)) confirm (file-exists-p filename))
+ (when (and confirm (file-exists-p filename))
(unless (y-or-n-p (format "File %s exists; overwrite anyway? " filename))
(tramp-error v 'file-error "File not overwritten")))
@@ -1161,7 +1218,9 @@ file-notify events."
;; Set file modification time.
(when (or (eq visit t) (stringp visit))
- (set-visited-file-modtime (nth 5 (file-attributes filename))))
+ (set-visited-file-modtime
+ (tramp-compat-file-attribute-modification-time
+ (file-attributes filename))))
;; The end.
(when (or (eq visit t) (null visit) (stringp visit))
@@ -1174,6 +1233,7 @@ file-notify events."
(defun tramp-gvfs-url-file-name (filename)
"Return FILENAME in URL syntax."
;; "/" must NOT be hexlified.
+ (setq filename (tramp-compat-file-name-unquote filename))
(let ((url-unreserved-chars (cons ?/ url-unreserved-chars))
result)
(setq
@@ -1181,6 +1241,8 @@ file-notify events."
(url-recreate-url
(if (tramp-tramp-file-p filename)
(with-parsed-tramp-file-name filename nil
+ (when (string-equal "gdrive" method)
+ (setq method "google-drive"))
(when (and user (string-match tramp-user-with-domain-regexp user))
(setq user
(concat (match-string 2 user) ";" (match-string 1 user))))
@@ -1203,8 +1265,7 @@ file-notify events."
(defun tramp-gvfs-file-name (object-path)
"Retrieve file name from D-Bus OBJECT-PATH."
(dbus-unescape-from-identifier
- (tramp-compat-replace-regexp-in-string
- "^.*/\\([^/]+\\)$" "\\1" object-path)))
+ (replace-regexp-in-string "^.*/\\([^/]+\\)$" "\\1" object-path)))
(defun tramp-bluez-address (device)
"Return bluetooth device address from a given bluetooth DEVICE name."
@@ -1293,7 +1354,7 @@ ADDRESS can have the form \"xx:xx:xx:xx:xx:xx\" or \"[xx:xx:xx:xx:xx:xx]\"."
;; host signature.
(with-temp-buffer
;; Preserve message for `progress-reporter'.
- (tramp-compat-with-temp-message ""
+ (with-temp-message ""
(insert message)
(pop-to-buffer (current-buffer))
(setq choice (if (yes-or-no-p (concat (car choices) " ")) 0 1))
@@ -1351,6 +1412,8 @@ ADDRESS can have the form \"xx:xx:xx:xx:xx:xx\" or \"[xx:xx:xx:xx:xx:xx]\"."
(setq host (tramp-bluez-device host)))
(when (and (string-equal "dav" method) (string-equal "true" ssl))
(setq method "davs"))
+ (when (string-equal "google-drive" method)
+ (setq method "gdrive"))
(unless (zerop (length domain))
(setq user (concat user tramp-prefix-domain-format domain)))
(unless (zerop (length port))
@@ -1362,13 +1425,13 @@ ADDRESS can have the form \"xx:xx:xx:xx:xx:xx\" or \"[xx:xx:xx:xx:xx:xx]\"."
signal-name (tramp-gvfs-stringify-dbus-message mount-info))
(tramp-set-file-property v "/" "list-mounts" 'undef)
(if (string-equal (downcase signal-name) "unmounted")
- (tramp-set-file-property v "/" "fuse-mountpoint" nil)
+ (tramp-flush-file-property v "/")
;; Set prefix, mountpoint and location.
(unless (string-equal prefix "/")
(tramp-set-file-property v "/" "prefix" prefix))
(tramp-set-file-property v "/" "fuse-mountpoint" fuse-mountpoint)
- (tramp-set-file-property
- v "/" "default-location" default-location)))))))
+ (tramp-set-connection-property
+ v "default-location" default-location)))))))
(when tramp-gvfs-enabled
(dbus-register-signal
@@ -1436,6 +1499,8 @@ ADDRESS can have the form \"xx:xx:xx:xx:xx:xx\" or \"[xx:xx:xx:xx:xx:xx]\"."
(setq host (tramp-bluez-device host)))
(when (and (string-equal "dav" method) (string-equal "true" ssl))
(setq method "davs"))
+ (when (string-equal "google-drive" method)
+ (setq method "gdrive"))
(when (and (string-equal "synce" method) (zerop (length user)))
(setq user (or (tramp-file-name-user vec) "")))
(unless (zerop (length domain))
@@ -1447,12 +1512,13 @@ ADDRESS can have the form \"xx:xx:xx:xx:xx:xx\" or \"[xx:xx:xx:xx:xx:xx]\"."
(string-equal user (or (tramp-file-name-user vec) ""))
(string-equal host (tramp-file-name-host vec))
(string-match (concat "^" (regexp-quote prefix))
- (tramp-file-name-localname vec)))
+ (tramp-file-name-unquote-localname vec)))
;; Set prefix, mountpoint and location.
(unless (string-equal prefix "/")
(tramp-set-file-property vec "/" "prefix" prefix))
(tramp-set-file-property vec "/" "fuse-mountpoint" fuse-mountpoint)
- (tramp-set-file-property vec "/" "default-location" default-location)
+ (tramp-set-connection-property
+ vec "default-location" default-location)
(throw 'mounted t)))))))
(defun tramp-gvfs-mount-spec-entry (key value)
@@ -1470,10 +1536,10 @@ It was \"a(say)\", but has changed to \"a{sv})\"."
(domain (tramp-file-name-domain vec))
(host (tramp-file-name-real-host vec))
(port (tramp-file-name-port vec))
- (localname (tramp-file-name-localname vec))
+ (localname (tramp-file-name-unquote-localname vec))
(share (when (string-match "^/?\\([^/]+\\)" localname)
(match-string 1 localname)))
- (ssl (when (string-match "^davs" method) "true" "false"))
+ (ssl (if (string-match "^davs" method) "true" "false"))
(mount-spec
`(:array
,@(cond
@@ -1493,6 +1559,9 @@ It was \"a(say)\", but has changed to \"a{sv})\"."
(list (tramp-gvfs-mount-spec-entry "type" "afp-volume")
(tramp-gvfs-mount-spec-entry "host" host)
(tramp-gvfs-mount-spec-entry "volume" share)))
+ ((string-equal "gdrive" method)
+ (list (tramp-gvfs-mount-spec-entry "type" "google-drive")
+ (tramp-gvfs-mount-spec-entry "host" host)))
(t
(list (tramp-gvfs-mount-spec-entry "type" method)
(tramp-gvfs-mount-spec-entry "host" host))))
@@ -1515,6 +1584,44 @@ It was \"a(say)\", but has changed to \"a{sv})\"."
;; Connection functions.
+(defun tramp-gvfs-get-remote-uid (vec id-format)
+ "The uid of the remote connection VEC, in ID-FORMAT.
+ID-FORMAT valid values are `string' and `integer'."
+ (with-tramp-connection-property vec (format "uid-%s" id-format)
+ (let ((method (tramp-file-name-method vec))
+ (user (tramp-file-name-user vec))
+ (host (tramp-file-name-host vec))
+ (localname
+ (tramp-get-connection-property vec "default-location" nil)))
+ (cond
+ ((and user (equal id-format 'string)) user)
+ (localname
+ (tramp-compat-file-attribute-user-id
+ (file-attributes
+ (tramp-make-tramp-file-name method user host localname) id-format)))
+ ((equal id-format 'integer) tramp-unknown-id-integer)
+ ((equal id-format 'string) tramp-unknown-id-string)))))
+
+(defun tramp-gvfs-get-remote-gid (vec id-format)
+ "The gid of the remote connection VEC, in ID-FORMAT.
+ID-FORMAT valid values are `string' and `integer'."
+ (with-tramp-connection-property vec (format "gid-%s" id-format)
+ (let ((method (tramp-file-name-method vec))
+ (user (tramp-file-name-user vec))
+ (host (tramp-file-name-host vec))
+ (localname
+ (tramp-get-connection-property vec "default-location" nil)))
+ (cond
+ (localname
+ (tramp-compat-file-attribute-group-id
+ (file-attributes
+ (tramp-make-tramp-file-name method user host localname) id-format)))
+ ((equal id-format 'integer) tramp-unknown-id-integer)
+ ((equal id-format 'string) tramp-unknown-id-string)))))
+
+(defvar tramp-gvfs-get-remote-uid-gid-in-progress nil
+ "Indication, that remote uid and gid determination is in progress.")
+
(defun tramp-gvfs-maybe-open-connection (vec)
"Maybe open a connection VEC.
Does not do anything if a connection is already open, but re-opens the
@@ -1532,26 +1639,26 @@ connection if a previous connection has died for some reason."
(let ((p (make-network-process
:name (tramp-buffer-name vec)
:buffer (tramp-get-connection-buffer vec)
- :server t :host 'local :service t)))
- (tramp-compat-set-process-query-on-exit-flag p nil)))
+ :server t :host 'local :service t :noquery t)))
+ (set-process-query-on-exit-flag p nil)))
(unless (tramp-gvfs-connection-mounted-p vec)
(let* ((method (tramp-file-name-method vec))
(user (tramp-file-name-user vec))
(host (tramp-file-name-host vec))
- (localname (tramp-file-name-localname vec))
+ (localname (tramp-file-name-unquote-localname vec))
(object-path
(tramp-gvfs-object-path
(tramp-make-tramp-file-name method user host ""))))
- (when (and (string-equal method "smb")
- (string-equal localname "/"))
- (tramp-error vec 'file-error "Filename must contain a Windows share"))
-
(when (and (string-equal method "afp")
(string-equal localname "/"))
(tramp-error vec 'file-error "Filename must contain an AFP volume"))
+ (when (and (string-equal method "smb")
+ (string-equal localname "/"))
+ (tramp-error vec 'file-error "Filename must contain a Windows share"))
+
(with-tramp-progress-reporter
vec 3
(if (zerop (length user))
@@ -1619,30 +1726,39 @@ connection if a previous connection has died for some reason."
(tramp-get-file-property vec "/" "fuse-mountpoint" "") "/")
(tramp-error vec 'file-error "FUSE mount denied"))
+ ;; Set connection-local variables.
+ (tramp-set-connection-local-variables vec)
+
;; Mark it as connected.
(tramp-set-connection-property
(tramp-get-connection-process vec) "connected" t))))
;; In `tramp-check-cached-permissions', the connection properties
- ;; {uig,gid}-{integer,string} are used. We set them to their local
- ;; counterparts.
- (with-tramp-connection-property
- vec "uid-integer" (tramp-get-local-uid 'integer))
- (with-tramp-connection-property
- vec "gid-integer" (tramp-get-local-gid 'integer))
- (with-tramp-connection-property
- vec "uid-string" (tramp-get-local-uid 'string))
- (with-tramp-connection-property
- vec "gid-string" (tramp-get-local-gid 'string)))
+ ;; {uig,gid}-{integer,string} are used. We set them to proper values.
+ (unless tramp-gvfs-get-remote-uid-gid-in-progress
+ (let ((tramp-gvfs-get-remote-uid-gid-in-progress t))
+ (tramp-gvfs-get-remote-uid vec 'integer)
+ (tramp-gvfs-get-remote-gid vec 'integer)
+ (tramp-gvfs-get-remote-uid vec 'string)
+ (tramp-gvfs-get-remote-gid vec 'string))))
(defun tramp-gvfs-send-command (vec command &rest args)
"Send the COMMAND with its ARGS to connection VEC.
COMMAND is usually a command from the gvfs-* utilities.
`call-process' is applied, and it returns t if the return code is zero."
- (with-current-buffer (tramp-get-connection-buffer vec)
- (tramp-gvfs-maybe-open-connection vec)
- (erase-buffer)
- (zerop (apply 'tramp-call-process vec command nil t nil args))))
+ (let* ((locale (tramp-get-local-locale vec))
+ (process-environment
+ (append
+ `(,(format "LANG=%s" locale)
+ ,(format "LANGUAGE=%s" locale)
+ ,(format "LC_ALL=%s" locale))
+ process-environment)))
+ (with-current-buffer (tramp-get-connection-buffer vec)
+ (tramp-gvfs-maybe-open-connection vec)
+ (erase-buffer)
+ (or (zerop (apply 'tramp-call-process vec command nil t nil args))
+ ;; Remove information about mounted connection.
+ (and (tramp-flush-file-property vec "/") nil)))))
;; D-Bus BLUEZ functions.
@@ -1755,7 +1871,7 @@ This uses \"avahi-browse\" in case D-Bus is not enabled in Avahi."
'split-string
(shell-command-to-string (format "avahi-browse -trkp %s" service))
"[\n\r]+" 'omit "^\\+;.*$"))))
- (tramp-compat-delete-dups
+ (delete-dups
(mapcar
(lambda (x)
(let* ((list (split-string x ";"))
@@ -1776,35 +1892,37 @@ This uses \"avahi-browse\" in case D-Bus is not enabled in Avahi."
;; Add completion functions for AFP, DAV, DAVS, SFTP and SMB methods.
(when tramp-gvfs-enabled
- (zeroconf-init tramp-gvfs-zeroconf-domain)
- (if (zeroconf-list-service-types)
- (progn
+ ;; Suppress D-Bus error messages.
+ (let (tramp-gvfs-dbus-event-vector)
+ (zeroconf-init tramp-gvfs-zeroconf-domain)
+ (if (zeroconf-list-service-types)
+ (progn
+ (tramp-set-completion-function
+ "afp" '((tramp-zeroconf-parse-device-names "_afpovertcp._tcp")))
+ (tramp-set-completion-function
+ "dav" '((tramp-zeroconf-parse-device-names "_webdav._tcp")))
+ (tramp-set-completion-function
+ "davs" '((tramp-zeroconf-parse-device-names "_webdav._tcp")))
+ (tramp-set-completion-function
+ "sftp" '((tramp-zeroconf-parse-device-names "_ssh._tcp")
+ (tramp-zeroconf-parse-device-names "_workstation._tcp")))
+ (when (member "smb" tramp-gvfs-methods)
+ (tramp-set-completion-function
+ "smb" '((tramp-zeroconf-parse-device-names "_smb._tcp")))))
+
+ (when (executable-find "avahi-browse")
(tramp-set-completion-function
- "afp" '((tramp-zeroconf-parse-device-names "_afpovertcp._tcp")))
+ "afp" '((tramp-gvfs-parse-device-names "_afpovertcp._tcp")))
(tramp-set-completion-function
- "dav" '((tramp-zeroconf-parse-device-names "_webdav._tcp")))
+ "dav" '((tramp-gvfs-parse-device-names "_webdav._tcp")))
(tramp-set-completion-function
- "davs" '((tramp-zeroconf-parse-device-names "_webdav._tcp")))
+ "davs" '((tramp-gvfs-parse-device-names "_webdav._tcp")))
(tramp-set-completion-function
- "sftp" '((tramp-zeroconf-parse-device-names "_ssh._tcp")
- (tramp-zeroconf-parse-device-names "_workstation._tcp")))
+ "sftp" '((tramp-gvfs-parse-device-names "_ssh._tcp")
+ (tramp-gvfs-parse-device-names "_workstation._tcp")))
(when (member "smb" tramp-gvfs-methods)
(tramp-set-completion-function
- "smb" '((tramp-zeroconf-parse-device-names "_smb._tcp")))))
-
- (when (executable-find "avahi-browse")
- (tramp-set-completion-function
- "afp" '((tramp-gvfs-parse-device-names "_afpovertcp._tcp")))
- (tramp-set-completion-function
- "dav" '((tramp-gvfs-parse-device-names "_webdav._tcp")))
- (tramp-set-completion-function
- "davs" '((tramp-gvfs-parse-device-names "_webdav._tcp")))
- (tramp-set-completion-function
- "sftp" '((tramp-gvfs-parse-device-names "_ssh._tcp")
- (tramp-gvfs-parse-device-names "_workstation._tcp")))
- (when (member "smb" tramp-gvfs-methods)
- (tramp-set-completion-function
- "smb" '((tramp-gvfs-parse-device-names "_smb._tcp")))))))
+ "smb" '((tramp-gvfs-parse-device-names "_smb._tcp"))))))))
;; D-Bus SYNCE functions.
@@ -1849,11 +1967,15 @@ They are retrieved from the hal daemon."
;;; TODO:
-;; * Host name completion via afp-server, smb-server or smb-network.
-;; * Check how two shares of the same SMB server can be mounted in
+;; * Host name completion for existing mount points (afp-server,
+;; smb-server) or via smb-network.
+;;
+;; * Check, how two shares of the same SMB server can be mounted in
;; parallel.
+;;
;; * Apply SDP on bluetooth devices, in order to filter out obex
;; capability.
+;;
;; * Implement obex for other serial communication but bluetooth.
;;; tramp-gvfs.el ends here
diff --git a/lisp/net/tramp-gw.el b/lisp/net/tramp-gw.el
deleted file mode 100644
index f868bead09a..00000000000
--- a/lisp/net/tramp-gw.el
+++ /dev/null
@@ -1,336 +0,0 @@
-;;; tramp-gw.el --- Tramp utility functions for HTTP tunnels and SOCKS gateways
-
-;; Copyright (C) 2007-2016 Free Software Foundation, Inc.
-
-;; Author: Michael Albinus <michael.albinus@gmx.de>
-;; Keywords: comm, processes
-;; Package: tramp
-
-;; 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 3 of the License, 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. If not, see <http://www.gnu.org/licenses/>.
-
-;;; Commentary:
-
-;; Access functions for HTTP tunnels and SOCKS gateways from Tramp.
-;; SOCKS functionality is implemented by socks.el from the w3 package.
-;; HTTP tunnels are partly implemented in socks.el and url-http.el;
-;; both implementations are not complete. Therefore, it is
-;; implemented in this package.
-
-;;; Code:
-
-(require 'tramp)
-
-;; Pacify byte-compiler.
-(eval-when-compile
- (require 'cl)
- (require 'custom))
-(defvar socks-noproxy)
-
-;; We don't add the following methods to `tramp-methods', in order to
-;; exclude them from file name completion.
-
-;; Define HTTP tunnel method ...
-;;;###tramp-autoload
-(defconst tramp-gw-tunnel-method "tunnel"
- "Method to connect HTTP gateways.")
-
-;; ... and port.
-(defconst tramp-gw-default-tunnel-port 8080
- "Default port for HTTP gateways.")
-
-;; Define SOCKS method ...
-;;;###tramp-autoload
-(defconst tramp-gw-socks-method "socks"
- "Method to connect SOCKS servers.")
-
-;; ... and port.
-(defconst tramp-gw-default-socks-port 1080
- "Default port for SOCKS servers.")
-
-;; Autoload the socks library. It is used only when we access a SOCKS server.
-(autoload 'socks-open-network-stream "socks")
-(defvar socks-username (user-login-name))
-(defvar socks-server
- (list "Default server" "socks" tramp-gw-default-socks-port 5))
-
-;; Add a default for `tramp-default-user-alist'. Default is the local user.
-;;;###tramp-autoload
-(add-to-list
- 'tramp-default-user-alist
- (list (concat "\\`"
- (regexp-opt (list tramp-gw-tunnel-method tramp-gw-socks-method))
- "\\'")
- nil (user-login-name)))
-
-;; Internal file name functions and variables.
-
-(defvar tramp-gw-vector nil
- "Keeps the remote host identification. Needed for Tramp messages.")
-
-(defvar tramp-gw-gw-vector nil
- "Current gateway identification vector.")
-
-(defvar tramp-gw-gw-proc nil
- "Current gateway process.")
-
-;; This variable keeps the listening process, in order to reuse it for
-;; new processes.
-(defvar tramp-gw-aux-proc nil
- "Process listening on local port, as mediation between SSH and the gateway.")
-
-(defun tramp-gw-gw-proc-sentinel (proc _event)
- "Delete auxiliary process when we are deleted."
- (unless (memq (process-status proc) '(run open))
- (tramp-message
- tramp-gw-vector 4 "Deleting auxiliary process `%s'" tramp-gw-gw-proc)
- (let* ((tramp-verbose 0)
- (p (tramp-get-connection-property proc "process" nil)))
- (when (processp p) (delete-process p)))))
-
-(defun tramp-gw-aux-proc-sentinel (proc _event)
- "Activate the different filters for involved gateway and auxiliary processes."
- (when (memq (process-status proc) '(run open))
- ;; A new process has been spawned from `tramp-gw-aux-proc'.
- (tramp-message
- tramp-gw-vector 4
- "Opening auxiliary process `%s', speaking with process `%s'"
- proc tramp-gw-gw-proc)
- (tramp-compat-set-process-query-on-exit-flag proc nil)
- ;; We don't want debug messages, because the corresponding debug
- ;; buffer might be undecided.
- (let ((tramp-verbose 0))
- (tramp-set-connection-property tramp-gw-gw-proc "process" proc)
- (tramp-set-connection-property proc "process" tramp-gw-gw-proc))
- ;; Set the process-filter functions for both processes.
- (set-process-filter proc 'tramp-gw-process-filter)
- (set-process-filter tramp-gw-gw-proc 'tramp-gw-process-filter)
- ;; There might be already some output from the gateway process.
- (with-current-buffer (process-buffer tramp-gw-gw-proc)
- (unless (= (point-min) (point-max))
- (let ((s (buffer-string)))
- (delete-region (point) (point-max))
- (tramp-gw-process-filter tramp-gw-gw-proc s))))))
-
-(defun tramp-gw-process-filter (proc string)
- (let ((tramp-verbose 0))
- ;; The other process might have been stopped already. We don't
- ;; want to be interrupted then.
- (ignore-errors
- (process-send-string
- (tramp-get-connection-property proc "process" nil) string))))
-
-;;;###tramp-autoload
-(defun tramp-gw-open-connection (vec gw-vec target-vec)
- "Open a remote connection to VEC (see `tramp-file-name' structure).
-Take GW-VEC as SOCKS or HTTP gateway, i.e. its method must be a
-gateway method. TARGET-VEC identifies where to connect to via
-the gateway, it can be different from VEC when there are more
-hops to be applied.
-
-It returns a string like \"localhost#port\", which must be used
-instead of the host name declared in TARGET-VEC."
-
- ;; Remember vectors for property retrieval.
- (setq tramp-gw-vector vec
- tramp-gw-gw-vector gw-vec)
-
- ;; Start listening auxiliary process.
- (unless (and (processp tramp-gw-aux-proc)
- (memq (process-status tramp-gw-aux-proc) '(listen)))
- (let ((aux-vec
- (vector "aux" (tramp-file-name-user gw-vec)
- (tramp-file-name-host gw-vec) nil nil)))
- (setq tramp-gw-aux-proc
- (make-network-process
- :name (tramp-buffer-name aux-vec) :buffer nil :host 'local
- :server t :noquery t :service t :coding 'binary))
- (set-process-sentinel tramp-gw-aux-proc 'tramp-gw-aux-proc-sentinel)
- (tramp-compat-set-process-query-on-exit-flag tramp-gw-aux-proc nil)
- (tramp-message
- vec 4 "Opening auxiliary process `%s', listening on port %d"
- tramp-gw-aux-proc (process-contact tramp-gw-aux-proc :service))))
-
- (let* ((gw-method
- (intern
- (tramp-find-method
- (tramp-file-name-method gw-vec)
- (tramp-file-name-user gw-vec)
- (tramp-file-name-host gw-vec))))
- (socks-username
- (tramp-find-user
- (tramp-file-name-method gw-vec)
- (tramp-file-name-user gw-vec)
- (tramp-file-name-host gw-vec)))
- ;; Declare the SOCKS server to be used.
- (socks-server
- (list "Tramp temporary socks server list"
- ;; Host name.
- (tramp-file-name-real-host gw-vec)
- ;; Port number.
- (or (tramp-file-name-port gw-vec)
- (case gw-method
- (tunnel tramp-gw-default-tunnel-port)
- (socks tramp-gw-default-socks-port)))
- ;; Type. We support only http and socks5, NO socks4.
- ;; 'http could be used when HTTP tunnel works in socks.el.
- 5))
- ;; The function to be called.
- (socks-function
- (case gw-method
- (tunnel 'tramp-gw-open-network-stream)
- (socks 'socks-open-network-stream)))
- socks-noproxy)
-
- ;; Open SOCKS process.
- (setq tramp-gw-gw-proc
- (funcall
- socks-function
- (let ((tramp-verbose 0)) (tramp-get-connection-name gw-vec))
- (let ((tramp-verbose 0)) (tramp-get-connection-buffer gw-vec))
- (tramp-file-name-real-host target-vec)
- (tramp-file-name-port target-vec)))
- (set-process-sentinel tramp-gw-gw-proc 'tramp-gw-gw-proc-sentinel)
- (set-process-coding-system tramp-gw-gw-proc 'binary 'binary)
- (tramp-compat-set-process-query-on-exit-flag tramp-gw-gw-proc nil)
- (tramp-message
- vec 4 "Opened %s process `%s'"
- (case gw-method ('tunnel "HTTP tunnel") ('socks "SOCKS"))
- tramp-gw-gw-proc)
-
- ;; Return the new host for gateway access.
- (format "localhost#%d" (process-contact tramp-gw-aux-proc :service))))
-
-(defun tramp-gw-open-network-stream (name buffer host service)
- "Open stream to proxy server HOST:SERVICE.
-Resulting process has name NAME and buffer BUFFER. If
-authentication is requested from proxy server, provide it."
- (let ((command (format (concat
- "CONNECT %s:%d HTTP/1.1\r\n"
- "Host: %s:%d\r\n"
- "Connection: keep-alive\r\n"
- "User-Agent: Tramp/%s\r\n")
- host service host service tramp-version))
- (authentication "")
- (first t)
- found proc)
-
- (while (not found)
- ;; Clean up.
- (when (processp proc) (delete-process proc))
- (with-current-buffer buffer (erase-buffer))
- ;; Open network stream.
- (setq proc (open-network-stream
- name buffer (nth 1 socks-server) (nth 2 socks-server)))
- (set-process-coding-system proc 'binary 'binary)
- (tramp-compat-set-process-query-on-exit-flag proc nil)
- ;; Send CONNECT command.
- (process-send-string proc (format "%s%s\r\n" command authentication))
- (tramp-message
- tramp-gw-vector 6 "\n%s"
- (format
- "%s%s\r\n" command
- (tramp-compat-replace-regexp-in-string ;; no password in trace!
- "Basic [^\r\n]+" "Basic xxxxx" authentication t)))
- (with-current-buffer buffer
- ;; Trap errors to be traced in the right trace buffer. Often,
- ;; proxies have a timeout of 60". We wait 65" in order to
- ;; receive an answer this case.
- (ignore-errors
- (let ((tramp-verbose 0))
- (tramp-wait-for-regexp proc 65 "\r?\n\r?\n")))
- ;; Check return code.
- (goto-char (point-min))
- (narrow-to-region
- (point-min)
- (or (search-forward-regexp "\r?\n\r?\n" nil t) (point-max)))
- (tramp-message tramp-gw-vector 6 "\n%s" (buffer-string))
- (goto-char (point-min))
- (search-forward-regexp "^HTTP/[1-9]\\.[0-9]" nil t)
- (case (condition-case nil (read (current-buffer)) (error))
- ;; Connected.
- (200 (setq found t))
- ;; We need basic authentication.
- (401 (setq authentication (tramp-gw-basic-authentication nil first)))
- ;; Access forbidden.
- (403 (tramp-error-with-buffer
- (current-buffer) tramp-gw-vector 'file-error
- "Connection to %s:%d forbidden." host service))
- ;; Target host not found.
- (404 (tramp-error-with-buffer
- (current-buffer) tramp-gw-vector 'file-error
- "Host %s not found." host))
- ;; We need basic proxy authentication.
- (407 (setq authentication (tramp-gw-basic-authentication t first)))
- ;; Connection failed.
- (503 (tramp-error-with-buffer
- (current-buffer) tramp-gw-vector 'file-error
- "Connection to %s:%d failed." host service))
- ;; That doesn't work at all.
- (t (tramp-error-with-buffer
- (current-buffer) tramp-gw-vector 'file-error
- "Access to HTTP server %s:%d failed."
- (nth 1 socks-server) (nth 2 socks-server))))
- ;; Remove HTTP headers.
- (delete-region (point-min) (point-max))
- (widen)
- (setq first nil)))
- ;; Return the process.
- proc))
-
-(defun tramp-gw-basic-authentication (proxy pw-cache)
- "Return authentication header for CONNECT, based on server request.
-PROXY is an indication whether we need a Proxy-Authorization header
-or an Authorization header. If PW-CACHE is non-nil, check for
-password in password cache. This is done for the first try only."
-
- ;; `tramp-current-*' must be set for `tramp-read-passwd'.
- (let ((tramp-current-method (tramp-file-name-method tramp-gw-gw-vector))
- (tramp-current-user (tramp-file-name-user tramp-gw-gw-vector))
- (tramp-current-host (tramp-file-name-host tramp-gw-gw-vector)))
- (unless pw-cache (tramp-clear-passwd tramp-gw-gw-vector))
- ;; We are already in the right buffer.
- (tramp-message
- tramp-gw-vector 5 "%s required"
- (if proxy "Proxy authentication" "Authentication"))
- ;; Search for request header. We accept only basic authentication.
- (goto-char (point-min))
- (search-forward-regexp
- "^\\(Proxy\\|WWW\\)-Authenticate:\\s-*Basic\\s-+realm=")
- ;; Return authentication string.
- (format
- "%s: Basic %s\r\n"
- (if proxy "Proxy-Authorization" "Authorization")
- (base64-encode-string
- (format
- "%s:%s"
- socks-username
- (tramp-read-passwd
- nil
- (format
- "Password for %s@[%s]: " socks-username (read (current-buffer)))))))))
-
-(add-hook 'tramp-unload-hook
- (lambda ()
- (unload-feature 'tramp-gw 'force)))
-
-(provide 'tramp-gw)
-
-;;; TODO:
-
-;; * Provide descriptive Commentary.
-;; * Enable it for several gateway processes in parallel.
-
-;;; tramp-gw.el ends here
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el
index 842b1ce2880..57cb6e11d21 100644
--- a/lisp/net/tramp-sh.el
+++ b/lisp/net/tramp-sh.el
@@ -32,9 +32,6 @@
(eval-when-compile
(require 'cl)
(require 'dired))
-(defvar directory-sep-char)
-(defvar tramp-gw-tunnel-method)
-(defvar tramp-gw-socks-method)
(defvar vc-handled-backends)
(defvar vc-bzr-program)
(defvar vc-git-program)
@@ -47,7 +44,8 @@ When inline transfer, compress transferred data of file
whose size is this value or above (up to `tramp-copy-size-limit').
If it is nil, no compression at all will be applied."
:group 'tramp
- :type '(choice (const nil) integer))
+ :type '(choice (const nil) integer)
+ :require 'tramp)
;;;###tramp-autoload
(defcustom tramp-copy-size-limit 10240
@@ -55,7 +53,8 @@ If it is nil, no compression at all will be applied."
out-of-the-band copy.
If it is nil, out-of-the-band copy will be used without a check."
:group 'tramp
- :type '(choice (const nil) integer))
+ :type '(choice (const nil) integer)
+ :require 'tramp)
;;;###tramp-autoload
(defcustom tramp-terminal-type "dumb"
@@ -64,7 +63,8 @@ Because Tramp wants to parse the output of the remote shell, it is easily
confused by ANSI color escape sequences and suchlike. Often, shell init
files conditionalize this setup based on the TERM environment variable."
:group 'tramp
- :type 'string)
+ :type 'string
+ :require 'tramp)
;;;###tramp-autoload
(defcustom tramp-histfile-override "~/.tramp_history"
@@ -81,11 +81,16 @@ the default storage location, e.g. \"$HOME/.sh_history\"."
:version "25.2"
:type '(choice (const :tag "Do not override HISTFILE" nil)
(const :tag "Unset HISTFILE" t)
- (string :tag "Redirect to a file")))
+ (string :tag "Redirect to a file"))
+ :require 'tramp)
;;;###tramp-autoload
-(defconst tramp-color-escape-sequence-regexp "\e[[;0-9]+m"
- "Escape sequences produced by the \"ls\" command.")
+(defconst tramp-display-escape-sequence-regexp "\e[[;0-9]+m"
+ "Terminal control escape sequences for display attributes.")
+
+;;;###tramp-autoload
+(defconst tramp-device-escape-sequence-regexp "\e[[0-9]+n"
+ "Terminal control escape sequences for device status.")
;; ksh on OpenBSD 4.5 requires that $PS1 contains a `#' character for
;; root users. It uses the `$' character for other users. In order
@@ -111,13 +116,14 @@ detected as prompt when being sent on echoing hosts, therefore.")
"Whether to use `tramp-ssh-controlmaster-options'."
:group 'tramp
:version "24.4"
- :type 'boolean)
+ :type 'boolean
+ :require 'tramp)
(defvar tramp-ssh-controlmaster-options nil
"Which ssh Control* arguments to use.
If it is a string, it should have the form
-\"-o ControlMaster=auto -o ControlPath='tramp.%%r@%%h:%%p'
+\"-o ControlMaster=auto -o ControlPath=\\='tramp.%%r@%%h:%%p\\='
-o ControlPersist=no\". Percent characters in the ControlPath
spec must be doubled, because the string is used as format string.
@@ -164,11 +170,7 @@ The string is used in `tramp-methods'.")
(tramp-copy-program "scp")
(tramp-copy-args (("-P" "%p") ("-p" "%k") ("-q") ("-r") ("%c")))
(tramp-copy-keep-date t)
- (tramp-copy-recursive t)
- (tramp-gw-args (("-o" "GlobalKnownHostsFile=/dev/null")
- ("-o" "UserKnownHostsFile=/dev/null")
- ("-o" "StrictHostKeyChecking=no")))
- (tramp-default-port 22)))
+ (tramp-copy-recursive t)))
;;;###tramp-autoload
(add-to-list 'tramp-methods
'("scpx"
@@ -183,11 +185,7 @@ The string is used in `tramp-methods'.")
(tramp-copy-args (("-P" "%p") ("-p" "%k")
("-q") ("-r") ("%c")))
(tramp-copy-keep-date t)
- (tramp-copy-recursive t)
- (tramp-gw-args (("-o" "GlobalKnownHostsFile=/dev/null")
- ("-o" "UserKnownHostsFile=/dev/null")
- ("-o" "StrictHostKeyChecking=no")))
- (tramp-default-port 22)))
+ (tramp-copy-recursive t)))
;;;###tramp-autoload
(add-to-list 'tramp-methods
'("rsync"
@@ -199,7 +197,7 @@ The string is used in `tramp-methods'.")
(tramp-remote-shell-login ("-l"))
(tramp-remote-shell-args ("-c"))
(tramp-copy-program "rsync")
- (tramp-copy-args (("-t" "%k") ("-r")))
+ (tramp-copy-args (("-t" "%k") ("-p") ("-r") ("-s")))
(tramp-copy-env (("RSYNC_RSH") ("ssh" "%c")))
(tramp-copy-keep-date t)
(tramp-copy-keep-tmpfile t)
@@ -229,11 +227,7 @@ The string is used in `tramp-methods'.")
(tramp-async-args (("-q")))
(tramp-remote-shell "/bin/sh")
(tramp-remote-shell-login ("-l"))
- (tramp-remote-shell-args ("-c"))
- (tramp-gw-args (("-o" "GlobalKnownHostsFile=/dev/null")
- ("-o" "UserKnownHostsFile=/dev/null")
- ("-o" "StrictHostKeyChecking=no")))
- (tramp-default-port 22)))
+ (tramp-remote-shell-args ("-c"))))
;;;###tramp-autoload
(add-to-list 'tramp-methods
'("sshx"
@@ -243,11 +237,7 @@ The string is used in `tramp-methods'.")
(tramp-async-args (("-q")))
(tramp-remote-shell "/bin/sh")
(tramp-remote-shell-login ("-l"))
- (tramp-remote-shell-args ("-c"))
- (tramp-gw-args (("-o" "GlobalKnownHostsFile=/dev/null")
- ("-o" "UserKnownHostsFile=/dev/null")
- ("-o" "StrictHostKeyChecking=no")))
- (tramp-default-port 22)))
+ (tramp-remote-shell-args ("-c"))))
;;;###tramp-autoload
(add-to-list 'tramp-methods
'("telnet"
@@ -255,8 +245,7 @@ The string is used in `tramp-methods'.")
(tramp-login-args (("%h") ("%p") ("2>/dev/null")))
(tramp-remote-shell "/bin/sh")
(tramp-remote-shell-login ("-l"))
- (tramp-remote-shell-args ("-c"))
- (tramp-default-port 23)))
+ (tramp-remote-shell-args ("-c"))))
;;;###tramp-autoload
(add-to-list 'tramp-methods
'("nc"
@@ -272,8 +261,7 @@ The string is used in `tramp-methods'.")
;; We use "-p" as required for newer busyboxes. For older
;; busybox/nc versions, the value must be (("-l") ("%r")). This
;; can be achieved by tweaking `tramp-connection-properties'.
- (tramp-remote-copy-args (("-l") ("-p" "%r") ("2>/dev/null")))
- (tramp-default-port 23)))
+ (tramp-remote-copy-args (("-l") ("-p" "%r") ("2>/dev/null")))))
;;;###tramp-autoload
(add-to-list 'tramp-methods
'("su"
@@ -284,6 +272,15 @@ The string is used in `tramp-methods'.")
(tramp-remote-shell-args ("-c"))
(tramp-connection-timeout 10)))
;;;###tramp-autoload
+(add-to-list
+ 'tramp-methods
+ '("sg"
+ (tramp-login-program "sg")
+ (tramp-login-args (("-") ("%u")))
+ (tramp-remote-shell "/bin/sh")
+ (tramp-remote-shell-args ("-c"))
+ (tramp-connection-timeout 10)))
+;;;###tramp-autoload
(add-to-list 'tramp-methods
'("sudo"
(tramp-login-program "sudo")
@@ -299,6 +296,14 @@ The string is used in `tramp-methods'.")
(tramp-connection-timeout 10)))
;;;###tramp-autoload
(add-to-list 'tramp-methods
+ '("doas"
+ (tramp-login-program "doas")
+ (tramp-login-args (("-u" "%u") ("-s")))
+ (tramp-remote-shell "/bin/sh")
+ (tramp-remote-shell-args ("-c"))
+ (tramp-connection-timeout 10)))
+;;;###tramp-autoload
+(add-to-list 'tramp-methods
'("ksu"
(tramp-login-program "ksu")
(tramp-login-args (("%u") ("-q")))
@@ -328,8 +333,7 @@ The string is used in `tramp-methods'.")
("/bin/sh") ("\"")))
(tramp-remote-shell "/bin/sh")
(tramp-remote-shell-login ("-l"))
- (tramp-remote-shell-args ("-c"))
- (tramp-default-port 22)))
+ (tramp-remote-shell-args ("-c"))))
;;;###tramp-autoload
(add-to-list 'tramp-methods
`("plinkx"
@@ -361,8 +365,7 @@ The string is used in `tramp-methods'.")
(tramp-copy-args (("-l" "%u") ("-P" "%p") ("-scp") ("-p" "%k")
("-q") ("-r")))
(tramp-copy-keep-date t)
- (tramp-copy-recursive t)
- (tramp-default-port 22)))
+ (tramp-copy-recursive t)))
;;;###tramp-autoload
(add-to-list 'tramp-methods
`("psftp"
@@ -379,9 +382,8 @@ The string is used in `tramp-methods'.")
(tramp-remote-shell-args ("-c"))
(tramp-copy-program "pscp")
(tramp-copy-args (("-l" "%u") ("-P" "%p") ("-sftp") ("-p" "%k")
- ("-q") ("-r")))
- (tramp-copy-keep-date t)
- (tramp-copy-recursive t)))
+ ("-q")))
+ (tramp-copy-keep-date t)))
;;;###tramp-autoload
(add-to-list 'tramp-methods
'("fcp"
@@ -400,7 +402,7 @@ The string is used in `tramp-methods'.")
;;;###tramp-autoload
(add-to-list 'tramp-default-user-alist
- `(,(concat "\\`" (regexp-opt '("su" "sudo" "ksu")) "\\'")
+ `(,(concat "\\`" (regexp-opt '("su" "sudo" "doas" "ksu")) "\\'")
nil "root"))
;; Do not add "ssh" based methods, otherwise ~/.ssh/config would be ignored.
;; Do not add "plink" based methods, they ask interactively for the user.
@@ -446,12 +448,17 @@ The string is used in `tramp-methods'.")
"Default list of (FUNCTION FILE) pairs to be examined for su methods.")
;;;###tramp-autoload
+(defconst tramp-completion-function-alist-sg
+ '((tramp-parse-etc-group "/etc/group"))
+ "Default list of (FUNCTION FILE) pairs to be examined for sg methods.")
+
+;;;###tramp-autoload
(defconst tramp-completion-function-alist-putty
`((tramp-parse-putty
,(if (memq system-type '(windows-nt))
"HKEY_CURRENT_USER\\Software\\SimonTatham\\PuTTY\\Sessions"
"~/.putty/sessions")))
- "Default list of (FUNCTION REGISTRY) pairs to be examined for putty sessions.")
+ "Default list of (FUNCTION REGISTRY) pairs to be examined for putty sessions.")
;;;###tramp-autoload
(eval-after-load 'tramp
@@ -470,7 +477,9 @@ The string is used in `tramp-methods'.")
(tramp-set-completion-function "nc" tramp-completion-function-alist-telnet)
(tramp-set-completion-function "su" tramp-completion-function-alist-su)
(tramp-set-completion-function "sudo" tramp-completion-function-alist-su)
+ (tramp-set-completion-function "doas" tramp-completion-function-alist-su)
(tramp-set-completion-function "ksu" tramp-completion-function-alist-su)
+ (tramp-set-completion-function "sg" tramp-completion-function-alist-sg)
(tramp-set-completion-function
"krlogin" tramp-completion-function-alist-rsh)
(tramp-set-completion-function "plink" tramp-completion-function-alist-ssh)
@@ -483,10 +492,11 @@ The string is used in `tramp-methods'.")
;; "getconf PATH" yields:
;; HP-UX: /usr/bin:/usr/ccs/bin:/opt/ansic/bin:/opt/langtools/bin:/opt/fortran/bin
;; Solaris: /usr/xpg4/bin:/usr/ccs/bin:/usr/bin:/opt/SUNWspro/bin
-;; GNU/Linux (Debian, Suse): /bin:/usr/bin
+;; GNU/Linux (Debian, Suse, RHEL): /bin:/usr/bin
;; FreeBSD: /usr/bin:/bin:/usr/sbin:/sbin: - beware trailing ":"!
;; Darwin: /usr/bin:/bin:/usr/sbin:/sbin
;; IRIX64: /usr/bin
+;; QNAP QTS: ---
;;;###tramp-autoload
(defcustom tramp-remote-path
'(tramp-default-remote-path "/bin" "/usr/bin" "/sbin" "/usr/sbin"
@@ -515,11 +525,12 @@ the list by the special value `tramp-own-remote-path'."
:type '(repeat (choice
(const :tag "Default Directories" tramp-default-remote-path)
(const :tag "Private Directories" tramp-own-remote-path)
- (string :tag "Directory"))))
+ (string :tag "Directory")))
+ :require 'tramp)
;;;###tramp-autoload
(defcustom tramp-remote-process-environment
- `("TMOUT=0" "LC_CTYPE=''"
+ `("ENV=''" "TMOUT=0" "LC_CTYPE=''"
,(format "TERM=%s" tramp-terminal-type)
,(format "INSIDE_EMACS='%s,tramp:%s'" emacs-version tramp-version)
"CDPATH=" "HISTORY=" "MAIL=" "MAILCHECK=" "MAILPATH=" "PAGER=cat"
@@ -533,8 +544,9 @@ which might have been set in the init files like ~/.profile.
Special handling is applied to the PATH environment, which should
not be set here. Instead, it should be set via `tramp-remote-path'."
:group 'tramp
- :version "24.4"
- :type '(repeat string))
+ :version "26.1"
+ :type '(repeat string)
+ :require 'tramp)
;;;###tramp-autoload
(defcustom tramp-sh-extra-args '(("/bash\\'" . "-norc -noprofile"))
@@ -551,7 +563,8 @@ shell from reading its init file."
;; `alist' is available. Who knows the right way to test it?
:type (if (get 'alist 'widget-type)
'(alist :key-type string :value-type string)
- '(repeat (cons string string))))
+ '(repeat (cons string string)))
+ :require 'tramp)
(defconst tramp-actions-before-shell
'((tramp-login-prompt-regexp tramp-action-login)
@@ -637,29 +650,19 @@ Escape sequence %s is replaced with name of Perl binary.
This string is passed to `format', so percent characters need to be doubled.")
(defconst tramp-perl-file-name-all-completions
- "%s -e 'sub case {
- my $str = shift;
- if ($ARGV[2]) {
- return lc($str);
- }
- else {
- return $str;
- }
-}
+ "%s -e '
opendir(d, $ARGV[0]) || die(\"$ARGV[0]: $!\\nfail\\n\");
@files = readdir(d); closedir(d);
foreach $f (@files) {
- if (case(substr($f, 0, length($ARGV[1]))) eq case($ARGV[1])) {
- if (-d \"$ARGV[0]/$f\") {
- print \"$f/\\n\";
- }
- else {
- print \"$f\\n\";
- }
+ if (-d \"$ARGV[0]/$f\") {
+ print \"$f/\\n\";
+ }
+ else {
+ print \"$f\\n\";
}
}
print \"ok\\n\"
-' \"$1\" \"$2\" \"$3\" 2>/dev/null"
+' \"$1\" 2>/dev/null"
"Perl script to produce output suitable for use with
`file-name-all-completions' on the remote file system. Escape
sequence %s is replaced with name of Perl binary. This string is
@@ -987,10 +990,7 @@ of command line.")
(directory-files . tramp-handle-directory-files)
(directory-files-and-attributes
. tramp-sh-handle-directory-files-and-attributes)
- ;; `dired-call-process' performed by default handler.
(dired-compress-file . tramp-sh-handle-dired-compress-file)
- (dired-recursive-delete-directory
- . tramp-sh-handle-dired-recursive-delete-directory)
(dired-uncache . tramp-handle-dired-uncache)
(expand-file-name . tramp-sh-handle-expand-file-name)
(file-accessible-directory-p . tramp-handle-file-accessible-directory-p)
@@ -1005,6 +1005,7 @@ of command line.")
(file-modes . tramp-handle-file-modes)
(file-name-all-completions . tramp-sh-handle-file-name-all-completions)
(file-name-as-directory . tramp-handle-file-name-as-directory)
+ (file-name-case-insensitive-p . tramp-handle-file-name-case-insensitive-p)
(file-name-completion . tramp-handle-file-name-completion)
(file-name-directory . tramp-handle-file-name-directory)
(file-name-nondirectory . tramp-handle-file-name-nondirectory)
@@ -1026,11 +1027,10 @@ of command line.")
;; `get-file-buffer' performed by default handler.
(insert-directory . tramp-sh-handle-insert-directory)
(insert-file-contents . tramp-handle-insert-file-contents)
- (insert-file-contents-literally
- . tramp-sh-handle-insert-file-contents-literally)
(load . tramp-handle-load)
(make-auto-save-file-name . tramp-handle-make-auto-save-file-name)
(make-directory . tramp-sh-handle-make-directory)
+ (make-nearby-temp-file . tramp-handle-make-nearby-temp-file)
(make-symbolic-link . tramp-sh-handle-make-symbolic-link)
(process-file . tramp-sh-handle-process-file)
(rename-file . tramp-sh-handle-rename-file)
@@ -1042,7 +1042,8 @@ of command line.")
(shell-command . tramp-handle-shell-command)
(start-file-process . tramp-sh-handle-start-file-process)
(substitute-in-file-name . tramp-handle-substitute-in-file-name)
- (unhandled-file-name-directory . tramp-handle-unhandled-file-name-directory)
+ (temporary-file-directory . tramp-handle-temporary-file-directory)
+ (unhandled-file-name-directory . ignore)
(vc-registered . tramp-sh-handle-vc-registered)
(verify-visited-file-modtime . tramp-sh-handle-verify-visited-file-modtime)
(write-region . tramp-sh-handle-write-region))
@@ -1123,7 +1124,9 @@ target of the symlink differ."
(tramp-make-tramp-file-name
method user host
(with-tramp-file-property v localname "file-truename"
- (let ((result nil)) ; result steps in reverse order
+ (let ((result nil) ; result steps in reverse order
+ (quoted (tramp-compat-file-name-quoted-p localname))
+ (localname (tramp-compat-file-name-unquote localname)))
(tramp-message v 4 "Finding true name for `%s'" filename)
(cond
;; Use GNU readlink --canonicalize-missing where available.
@@ -1149,10 +1152,8 @@ target of the symlink differ."
(format "tramp_perl_file_truename %s"
(tramp-shell-quote-argument localname)))))
- ;; Do it yourself. We bind `directory-sep-char' here for
- ;; XEmacs on Windows, which would otherwise use backslash.
- (t (let ((directory-sep-char ?/)
- (steps (tramp-compat-split-string localname "/"))
+ ;; Do it yourself.
+ (t (let ((steps (split-string localname "/" 'omit))
(thisstep nil)
(numchase 0)
;; Don't make the following value larger than
@@ -1170,14 +1171,15 @@ target of the symlink differ."
(append '("") (reverse result) (list thisstep))
"/"))
(setq symlink-target
- (nth 0 (file-attributes
- (tramp-make-tramp-file-name
- method user host
- (mapconcat 'identity
- (append '("")
- (reverse result)
- (list thisstep))
- "/")))))
+ (tramp-compat-file-attribute-type
+ (file-attributes
+ (tramp-make-tramp-file-name
+ method user host
+ (mapconcat 'identity
+ (append '("")
+ (reverse result)
+ (list thisstep))
+ "/")))))
(cond ((string= "." thisstep)
(tramp-message v 5 "Ignoring step `.'"))
((string= ".." thisstep)
@@ -1201,9 +1203,8 @@ target of the symlink differ."
symlink-target))
(setq symlink-target localname))
(setq steps
- (append (tramp-compat-split-string
- symlink-target "/")
- steps)))
+ (append
+ (split-string symlink-target "/" 'omit) steps)))
(t
;; It's a file.
(setq result (cons thisstep result)))))
@@ -1220,6 +1221,7 @@ target of the symlink differ."
(when (string= "" result)
(setq result "/")))))
+ (when quoted (setq result (tramp-compat-file-name-quote result)))
(tramp-message v 4 "True name of `%s' is `%s'" localname result)
result))))
@@ -1326,8 +1328,10 @@ target of the symlink differ."
(setq res-gid (read (current-buffer)))
(if (eq id-format 'integer)
(progn
- (unless (numberp res-uid) (setq res-uid -1))
- (unless (numberp res-gid) (setq res-gid -1)))
+ (unless (numberp res-uid)
+ (setq res-uid tramp-unknown-id-integer))
+ (unless (numberp res-gid)
+ (setq res-gid tramp-unknown-id-integer)))
(progn
(unless (stringp res-uid) (setq res-uid (symbol-name res-uid)))
(unless (stringp res-gid) (setq res-gid (symbol-name res-gid)))))
@@ -1356,8 +1360,8 @@ target of the symlink differ."
res-gid
;; 4. Last access time, as a list of integers. Normally
;; this would be in the same format as `current-time', but
- ;; the subseconds part is not currently implemented, and (0
- ;; 0) denotes an unknown time.
+ ;; the subseconds part is not currently implemented, and
+ ;; (0 0) denotes an unknown time.
;; 5. Last modification time, likewise.
;; 6. Last status change time, likewise.
'(0 0) '(0 0) '(0 0) ;CCC how to find out?
@@ -1371,8 +1375,7 @@ target of the symlink differ."
;; 10. Inode number.
res-inode
;; 11. Device number. Will be replaced by a virtual device number.
- -1
- ))))))
+ -1))))))
(defun tramp-do-file-attributes-with-perl
(vec localname &optional id-format)
@@ -1428,9 +1431,9 @@ target of the symlink differ."
(let* ((remote-file-name-inhibit-cache t)
(attr (file-attributes f))
;; '(-1 65535) means file doesn't exists yet.
- (modtime (or (nth 5 attr) '(-1 65535))))
- (when (boundp 'last-coding-system-used)
- (setq coding-system-used (symbol-value 'last-coding-system-used)))
+ (modtime (or (tramp-compat-file-attribute-modification-time attr)
+ '(-1 65535))))
+ (setq coding-system-used last-coding-system-used)
;; We use '(0 0) as a don't-know value. See also
;; `tramp-do-file-attributes-with-ls'.
(if (not (equal modtime '(0 0)))
@@ -1444,8 +1447,7 @@ target of the symlink differ."
(setq attr (buffer-substring (point) (point-at-eol))))
(tramp-set-file-property
v localname "visited-file-modtime-ild" attr))
- (when (boundp 'last-coding-system-used)
- (set 'last-coding-system-used coding-system-used))
+ (setq last-coding-system-used coding-system-used)
nil)))))
;; This function makes the same assumption as
@@ -1464,12 +1466,12 @@ of."
;; connection.
(if (or (not f)
(eq (visited-file-modtime) 0)
- (not (tramp-file-name-handler 'file-remote-p f nil 'connected)))
+ (not (file-remote-p f nil 'connected)))
t
(with-parsed-tramp-file-name f nil
(let* ((remote-file-name-inhibit-cache t)
(attr (file-attributes f))
- (modtime (nth 5 attr))
+ (modtime (tramp-compat-file-attribute-modification-time attr))
(mt (visited-file-modtime)))
(cond
@@ -1509,48 +1511,26 @@ of."
;; FIXME: extract the proper text from chmod's stderr.
(tramp-barf-unless-okay
v
- (format "chmod %s %s"
- (tramp-compat-decimal-to-octal mode)
- (tramp-shell-quote-argument localname))
+ (format "chmod %o %s" mode (tramp-shell-quote-argument localname))
"Error while changing file's mode %s" filename)))
(defun tramp-sh-handle-set-file-times (filename &optional time)
"Like `set-file-times' for Tramp files."
- (if (tramp-tramp-file-p filename)
- (with-parsed-tramp-file-name filename nil
- (when (tramp-get-remote-touch v)
- (tramp-flush-file-property v (file-name-directory localname))
- (tramp-flush-file-property v localname)
- (let ((time (if (or (null time) (equal time '(0 0)))
- (current-time)
- time))
- ;; With GNU Emacs, `format-time-string' has an
- ;; optional parameter ZONE. This is preferred,
- ;; because we could handle the case when the remote
- ;; host is located in a different time zone as the
- ;; local host.
- (utc (not (featurep 'xemacs))))
- (tramp-send-command-and-check
- v (format
- "%s %s %s %s"
- (if utc "env TZ=UTC" "")
- (tramp-get-remote-touch v)
- (if (tramp-get-connection-property v "touch-t" nil)
- (format "-t %s"
- (if utc
- (format-time-string "%Y%m%d%H%M.%S" time t)
- (format-time-string "%Y%m%d%H%M.%S" time)))
- "")
- (tramp-shell-quote-argument localname))))))
-
- ;; We handle also the local part, because in older Emacsen,
- ;; without `set-file-times', this function is an alias for this.
- ;; We are local, so we don't need the UTC settings.
- (zerop
- (tramp-call-process
- nil "touch" nil nil nil "-t"
- (format-time-string "%Y%m%d%H%M.%S" time)
- (tramp-shell-quote-argument filename)))))
+ (with-parsed-tramp-file-name filename nil
+ (when (tramp-get-remote-touch v)
+ (tramp-flush-file-property v (file-name-directory localname))
+ (tramp-flush-file-property v localname)
+ (let ((time (if (or (null time) (equal time '(0 0)))
+ (current-time)
+ time)))
+ (tramp-send-command-and-check
+ v (format
+ "env TZ=UTC %s %s %s"
+ (tramp-get-remote-touch v)
+ (if (tramp-get-connection-property v "touch-t" nil)
+ (format "-t %s" (format-time-string "%Y%m%d%H%M.%S" time t))
+ "")
+ (tramp-shell-quote-argument localname)))))))
(defun tramp-set-file-uid-gid (filename &optional uid gid)
"Set the ownership for FILENAME.
@@ -1654,8 +1634,7 @@ be non-negative integers."
(goto-char (point-max))
(delete-blank-lines)
(when (> (point-max) (point-min))
- (tramp-compat-funcall
- 'substring-no-properties (buffer-string))))))))
+ (substring-no-properties (buffer-string))))))))
(defun tramp-sh-handle-set-file-acl (filename acl-string)
"Like `set-file-acl' for Tramp files."
@@ -1716,9 +1695,16 @@ be non-negative integers."
;; and obtain the result.
(let ((fa1 (file-attributes file1))
(fa2 (file-attributes file2)))
- (if (and (not (equal (nth 5 fa1) '(0 0)))
- (not (equal (nth 5 fa2) '(0 0))))
- (> 0 (tramp-time-diff (nth 5 fa2) (nth 5 fa1)))
+ (if (and
+ (not
+ (equal (tramp-compat-file-attribute-modification-time fa1)
+ '(0 0)))
+ (not
+ (equal (tramp-compat-file-attribute-modification-time fa2)
+ '(0 0))))
+ (> 0 (tramp-time-diff
+ (tramp-compat-file-attribute-modification-time fa2)
+ (tramp-compat-file-attribute-modification-time fa1)))
;; If one of them is the dont-know value, then we can
;; still try to run a shell command on the remote host.
;; However, this only works if both files are Tramp
@@ -1770,9 +1756,11 @@ be non-negative integers."
;; information would be lost by an (attempted) delete and create.
(or (null attributes)
(and
- (= (nth 2 attributes) (tramp-get-remote-uid v 'integer))
+ (= (tramp-compat-file-attribute-user-id attributes)
+ (tramp-get-remote-uid v 'integer))
(or (not group)
- (= (nth 3 attributes) (tramp-get-remote-gid v 'integer)))))))))
+ (= (tramp-compat-file-attribute-group-id attributes)
+ (tramp-get-remote-gid v 'integer)))))))))
;; Directory listings.
@@ -1875,142 +1863,62 @@ be non-negative integers."
(defun tramp-sh-handle-file-name-all-completions (filename directory)
"Like `file-name-all-completions' for Tramp files."
(unless (save-match-data (string-match "/" filename))
- (with-parsed-tramp-file-name (expand-file-name directory) nil
+ (all-completions
+ filename
+ (with-parsed-tramp-file-name (expand-file-name directory) nil
+ (with-tramp-file-property v localname "file-name-all-completions"
+ (let (result)
+ ;; Get a list of directories and files, including reliably
+ ;; tagging the directories with a trailing "/". Because I
+ ;; rock. --daniel@danann.net
+ (tramp-send-command
+ v
+ (if (tramp-get-remote-perl v)
+ (progn
+ (tramp-maybe-send-script
+ v tramp-perl-file-name-all-completions
+ "tramp_perl_file_name_all_completions")
+ (format "tramp_perl_file_name_all_completions %s"
+ (tramp-shell-quote-argument localname)))
+
+ (format (concat
+ "(cd %s 2>&1 && %s -a 2>/dev/null"
+ " | while IFS= read f; do"
+ " if %s -d \"$f\" 2>/dev/null;"
+ " then \\echo \"$f/\"; else \\echo \"$f\"; fi; done"
+ " && \\echo ok) || \\echo fail")
+ (tramp-shell-quote-argument localname)
+ (tramp-get-ls-command v)
+ (tramp-get-test-command v))))
- (all-completions
- filename
- (mapcar
- 'list
- (or
- ;; Try cache entries for `filename', `filename' with last
- ;; character removed, `filename' with last two characters
- ;; removed, ..., and finally the empty string - all
- ;; concatenated to the local directory name.
- (let ((remote-file-name-inhibit-cache
- (or remote-file-name-inhibit-cache
- tramp-completion-reread-directory-timeout)))
-
- ;; This is inefficient for very long file names, pity
- ;; `reduce' is not available...
- (car
- (apply
- 'append
- (mapcar
- (lambda (x)
- (let ((cache-hit
- (tramp-get-file-property
- v
- (concat localname (substring filename 0 x))
- "file-name-all-completions"
- nil)))
- (when cache-hit (list cache-hit))))
- ;; We cannot use a length of 0, because file properties
- ;; for "foo" and "foo/" are identical.
- (tramp-compat-number-sequence (length filename) 1 -1)))))
-
- ;; Cache expired or no matching cache entry found so we need
- ;; to perform a remote operation.
- (let (result)
- ;; Get a list of directories and files, including reliably
- ;; tagging the directories with a trailing '/'. Because I
- ;; rock. --daniel@danann.net
-
- ;; Changed to perform `cd' in the same remote op and only
- ;; get entries starting with `filename'. Capture any `cd'
- ;; error messages. Ensure any `cd' and `echo' aliases are
- ;; ignored.
- (tramp-send-command
- v
- (if (tramp-get-remote-perl v)
- (progn
- (tramp-maybe-send-script
- v tramp-perl-file-name-all-completions
- "tramp_perl_file_name_all_completions")
- (format "tramp_perl_file_name_all_completions %s %s %d"
- (tramp-shell-quote-argument localname)
- (tramp-shell-quote-argument filename)
- (if (symbol-value
- ;; `read-file-name-completion-ignore-case'
- ;; is introduced with Emacs 22.1.
- (if (boundp
- 'read-file-name-completion-ignore-case)
- 'read-file-name-completion-ignore-case
- 'completion-ignore-case))
- 1 0)))
-
- (format (concat
- "(cd %s 2>&1 && (%s -a %s 2>/dev/null"
- ;; `ls' with wildcard might fail with `Argument
- ;; list too long' error in some corner cases; if
- ;; `ls' fails after `cd' succeeded, chances are
- ;; that's the case, so let's retry without
- ;; wildcard. This will return "too many" entries
- ;; but that isn't harmful.
- " || %s -a 2>/dev/null)"
- " | while IFS= read f; do"
- " if %s -d \"$f\" 2>/dev/null;"
- " then \\echo \"$f/\"; else \\echo \"$f\"; fi; done"
- " && \\echo ok) || \\echo fail")
- (tramp-shell-quote-argument localname)
- (tramp-get-ls-command v)
- ;; When `filename' is empty, just `ls' without
- ;; `filename' argument is more efficient than `ls *'
- ;; for very large directories and might avoid the
- ;; `Argument list too long' error.
- ;;
- ;; With and only with wildcard, we need to add
- ;; `-d' to prevent `ls' from descending into
- ;; sub-directories.
- (if (zerop (length filename))
- "."
- (format "-d %s*" (tramp-shell-quote-argument filename)))
- (tramp-get-ls-command v)
- (tramp-get-test-command v))))
-
- ;; Now grab the output.
- (with-current-buffer (tramp-get-buffer v)
- (goto-char (point-max))
-
- ;; Check result code, found in last line of output.
- (forward-line -1)
- (if (looking-at "^fail$")
- (progn
- ;; Grab error message from line before last line
- ;; (it was put there by `cd 2>&1').
- (forward-line -1)
- (tramp-error
- v 'file-error
- "tramp-sh-handle-file-name-all-completions: %s"
- (buffer-substring (point) (point-at-eol))))
- ;; For peace of mind, if buffer doesn't end in `fail'
- ;; then it should end in `ok'. If neither are in the
- ;; buffer something went seriously wrong on the remote
- ;; side.
- (unless (looking-at "^ok$")
- (tramp-error
- v 'file-error
- "\
+ ;; Now grab the output.
+ (with-current-buffer (tramp-get-buffer v)
+ (goto-char (point-max))
+
+ ;; Check result code, found in last line of output.
+ (forward-line -1)
+ (if (looking-at "^fail$")
+ (progn
+ ;; Grab error message from line before last line
+ ;; (it was put there by `cd 2>&1').
+ (forward-line -1)
+ (tramp-error
+ v 'file-error
+ "tramp-sh-handle-file-name-all-completions: %s"
+ (buffer-substring (point) (point-at-eol))))
+ ;; For peace of mind, if buffer doesn't end in `fail'
+ ;; then it should end in `ok'. If neither are in the
+ ;; buffer something went seriously wrong on the remote
+ ;; side.
+ (unless (looking-at "^ok$")
+ (tramp-error
+ v 'file-error "\
tramp-sh-handle-file-name-all-completions: internal error accessing `%s': `%s'"
- (tramp-shell-quote-argument localname) (buffer-string))))
+ (tramp-shell-quote-argument localname) (buffer-string))))
- (while (zerop (forward-line -1))
- (push (buffer-substring (point) (point-at-eol)) result)))
-
- ;; Because the remote op went through OK we know the
- ;; directory we `cd'-ed to exists.
- (tramp-set-file-property v localname "file-exists-p" t)
-
- ;; Because the remote op went through OK we know every
- ;; file listed by `ls' exists.
- (mapc (lambda (entry)
- (tramp-set-file-property
- v (concat localname entry) "file-exists-p" t))
- result)
-
- ;; Store result in the cache.
- (tramp-set-file-property
- v (concat localname filename)
- "file-name-all-completions" result))))))))
+ (while (zerop (forward-line -1))
+ (push (buffer-substring (point) (point-at-eol)) result)))
+ result))))))
;; cp, mv and ln
@@ -2034,7 +1942,8 @@ tramp-sh-handle-file-name-all-completions: internal error accessing `%s': `%s'"
"File %s already exists; make it a new name anyway? "
newname)))
(tramp-error
- v2 'file-error "add-name-to-file: file %s already exists" newname))
+ v2 'file-already-exists
+ "add-name-to-file: file %s already exists" newname))
(when ok-if-already-exists (setq ln (concat ln " -f")))
(tramp-flush-file-property v2 (file-name-directory v2-localname))
(tramp-flush-file-property v2 v2-localname)
@@ -2048,7 +1957,7 @@ tramp-sh-handle-file-name-all-completions: internal error accessing `%s': `%s'"
(defun tramp-sh-handle-copy-file
(filename newname &optional ok-if-already-exists keep-date
- preserve-uid-gid preserve-extended-attributes)
+ preserve-uid-gid preserve-extended-attributes)
"Like `copy-file' for Tramp files."
(setq filename (expand-file-name filename))
(setq newname (expand-file-name newname))
@@ -2059,19 +1968,18 @@ tramp-sh-handle-file-name-all-completions: internal error accessing `%s': `%s'"
(tramp-do-copy-or-rename-file
'copy filename newname ok-if-already-exists keep-date
preserve-uid-gid preserve-extended-attributes))
- ;; Compat section.
+ ;; Compat section. PRESERVE-EXTENDED-ATTRIBUTES has been
+ ;; introduced with Emacs 24.1 (as PRESERVE-SELINUX-CONTEXT), and
+ ;; renamed in Emacs 24.3.
(preserve-extended-attributes
(tramp-run-real-handler
'copy-file
(list filename newname ok-if-already-exists keep-date
preserve-uid-gid preserve-extended-attributes)))
- (preserve-uid-gid
- (tramp-run-real-handler
- 'copy-file
- (list filename newname ok-if-already-exists keep-date preserve-uid-gid)))
(t
(tramp-run-real-handler
- 'copy-file (list filename newname ok-if-already-exists keep-date)))))
+ 'copy-file
+ (list filename newname ok-if-already-exists keep-date preserve-uid-gid)))))
(defun tramp-sh-handle-copy-directory
(dirname newname &optional keep-date parents copy-contents)
@@ -2126,13 +2034,14 @@ tramp-sh-handle-file-name-all-completions: internal error accessing `%s': `%s'"
(if (or (tramp-tramp-file-p filename)
(tramp-tramp-file-p newname))
(tramp-do-copy-or-rename-file
- 'rename filename newname ok-if-already-exists t t)
+ 'rename filename newname ok-if-already-exists
+ 'keep-time 'preserve-uid-gid)
(tramp-run-real-handler
'rename-file (list filename newname ok-if-already-exists))))
(defun tramp-do-copy-or-rename-file
(op filename newname &optional ok-if-already-exists keep-date
- preserve-uid-gid preserve-extended-attributes)
+ preserve-uid-gid preserve-extended-attributes)
"Copy or rename a remote file.
OP must be `copy' or `rename' and indicates the operation to perform.
FILENAME specifies the file to copy or rename, NEWNAME is the name of
@@ -2151,7 +2060,8 @@ file names."
(error "Unknown operation `%s', must be `copy' or `rename'" op))
(let ((t1 (tramp-tramp-file-p filename))
(t2 (tramp-tramp-file-p newname))
- (length (nth 7 (file-attributes (file-truename filename))))
+ (length (tramp-compat-file-attribute-size
+ (file-attributes (file-truename filename))))
(attributes (and preserve-extended-attributes
(apply 'file-extended-attributes (list filename)))))
@@ -2262,7 +2172,11 @@ KEEP-DATE is non-nil if NEWNAME should have the same timestamp as FILENAME."
(set-buffer-multibyte nil)
(insert-file-contents-literally filename)))
;; KEEP-DATE handling.
- (when keep-date (set-file-times newname (nth 5 (file-attributes filename))))
+ (when keep-date
+ (set-file-times
+ newname
+ (tramp-compat-file-attribute-modification-time
+ (file-attributes filename))))
;; Set the mode.
(set-file-modes newname (tramp-default-file-modes filename))
;; If the operation was `rename', delete the original file.
@@ -2280,7 +2194,8 @@ as FILENAME. PRESERVE-UID-GID, when non-nil, instructs to keep
the uid and gid from FILENAME."
(let ((t1 (tramp-tramp-file-p filename))
(t2 (tramp-tramp-file-p newname))
- (file-times (nth 5 (file-attributes filename)))
+ (file-times (tramp-compat-file-attribute-modification-time
+ (file-attributes filename)))
(file-modes (tramp-default-file-modes filename)))
(with-parsed-tramp-file-name (if t1 filename newname) nil
(let* ((cmd (cond ((and (eq op 'copy) preserve-uid-gid) "cp -f -p")
@@ -2290,14 +2205,8 @@ the uid and gid from FILENAME."
v 'file-error
"Unknown operation `%s', must be `copy' or `rename'"
op))))
- (localname1
- (if t1
- (tramp-file-name-handler 'file-remote-p filename 'localname)
- filename))
- (localname2
- (if t2
- (tramp-file-name-handler 'file-remote-p newname 'localname)
- newname))
+ (localname1 (if t1 (file-remote-p filename 'localname) filename))
+ (localname2 (if t2 (file-remote-p newname 'localname) newname))
(prefix (file-remote-p (if t1 filename newname)))
cmd-result)
@@ -2334,12 +2243,12 @@ the uid and gid from FILENAME."
(zerop
(logand
(file-modes (file-name-directory localname1))
- (tramp-compat-octal-to-decimal "1000"))))
+ (string-to-number "1000" 8))))
(file-writable-p (file-name-directory localname2))
(or (file-directory-p localname2)
(file-writable-p localname2))))
(if (eq op 'copy)
- (tramp-compat-copy-file
+ (copy-file
localname1 localname2 ok-if-already-exists
keep-date preserve-uid-gid)
(tramp-run-real-handler
@@ -2379,25 +2288,21 @@ the uid and gid from FILENAME."
;; Since this does not work reliable, we also
;; give read permissions.
(set-file-modes
- (concat prefix tmpfile)
- (tramp-compat-octal-to-decimal "0777"))
+ (concat prefix tmpfile) (string-to-number "0777" 8))
(tramp-set-file-uid-gid
(concat prefix tmpfile)
(tramp-get-local-uid 'integer)
(tramp-get-local-gid 'integer)))
(t2
(if (eq op 'copy)
- (tramp-compat-copy-file
- localname1 tmpfile t
- keep-date preserve-uid-gid)
+ (copy-file
+ localname1 tmpfile t keep-date preserve-uid-gid)
(tramp-run-real-handler
- 'rename-file
- (list localname1 tmpfile t)))
+ 'rename-file (list localname1 tmpfile t)))
;; We must change the ownership as local user.
;; Since this does not work reliable, we also
;; give read permissions.
- (set-file-modes
- tmpfile (tramp-compat-octal-to-decimal "0777"))
+ (set-file-modes tmpfile (string-to-number "0777" 8))
(tramp-set-file-uid-gid
tmpfile
(tramp-get-remote-uid v 'integer)
@@ -2456,7 +2361,7 @@ The method used must be an out-of-band method."
;; Save exit.
(ignore-errors
(if dir-flag
- (tramp-compat-delete-directory
+ (delete-directory
(expand-file-name ".." tmpfile) 'recursive)
(delete-file tmpfile)))))
@@ -2468,35 +2373,22 @@ The method used must be an out-of-band method."
v "login-as" nil))
tramp-current-host (tramp-file-name-real-host v))
- ;; Expand hops. Might be necessary for gateway methods.
- (setq v (car (tramp-compute-multi-hops v)))
- (aset v 3 localname)
-
;; Check which ones of source and target are Tramp files.
- (setq source (if t1
- (tramp-make-copy-program-file-name v)
- (shell-quote-argument filename))
- target (if t2
- (tramp-make-copy-program-file-name v)
- (shell-quote-argument
- (funcall
+ (setq source (funcall
(if (and (file-directory-p filename)
- (string-equal
- (file-name-nondirectory filename)
- (file-name-nondirectory newname)))
- 'file-name-directory
+ (not (file-exists-p newname)))
+ 'file-name-as-directory
'identity)
- newname))))
-
- ;; Check for host and port number. We cannot use
- ;; `tramp-file-name-port', because this returns also
- ;; `tramp-default-port', which might clash with settings in
- ;; "~/.ssh/config".
- (setq host (tramp-file-name-host v)
- port "")
- (when (string-match tramp-host-with-port-regexp host)
- (setq port (string-to-number (match-string 2 host))
- host (string-to-number (match-string 1 host))))
+ (if t1
+ (tramp-make-copy-program-file-name v)
+ (tramp-unquote-shell-quote-argument filename)))
+ target (if t2
+ (tramp-make-copy-program-file-name v)
+ (tramp-unquote-shell-quote-argument newname)))
+
+ ;; Check for host and port number.
+ (setq host (tramp-file-name-real-host v)
+ port (tramp-file-name-port v))
;; Check for user. There might be an interactive setting.
(setq user (or (tramp-file-name-user v)
@@ -2615,43 +2507,26 @@ The method used must be an out-of-band method."
;; Use an asynchronous process. By this, password can
;; be handled. We don't set a timeout, because the
- ;; copying of large files can last longer than 60
- ;; secs.
- (let ((p (apply 'start-process-shell-command
- (tramp-get-connection-name v)
- (tramp-get-connection-buffer v)
- copy-program
- (append
- copy-args
- (list "&&" "echo" "tramp_exit_status" "0"
- "||" "echo" "tramp_exit_status" "1")))))
- (tramp-message
- orig-vec 6 "%s"
- (mapconcat 'identity (process-command p) " "))
+ ;; copying of large files can last longer than 60 secs.
+ (let* ((command
+ (mapconcat
+ 'identity (append (list copy-program) copy-args)
+ " "))
+ (p (let ((default-directory
+ (tramp-compat-temporary-file-directory)))
+ (start-process-shell-command
+ (tramp-get-connection-name v)
+ (tramp-get-connection-buffer v)
+ command))))
+ (tramp-message orig-vec 6 "%s" command)
(tramp-set-connection-property p "vector" orig-vec)
- (tramp-compat-set-process-query-on-exit-flag p nil)
+ (set-process-query-on-exit-flag p nil)
;; We must adapt `tramp-local-end-of-line' for
;; sending the password.
(let ((tramp-local-end-of-line tramp-rsh-end-of-line))
(tramp-process-actions
- p v nil tramp-actions-copy-out-of-band))
-
- ;; Check the return code.
- (goto-char (point-max))
- (unless
- (re-search-backward "tramp_exit_status [0-9]+" nil t)
- (tramp-error
- orig-vec 'file-error
- "Couldn't find exit status of `%s'"
- (mapconcat 'identity (process-command p) " ")))
- (skip-chars-forward "^ ")
- (unless (zerop (read (current-buffer)))
- (forward-line -1)
- (tramp-error
- orig-vec 'file-error
- "Error copying: `%s'"
- (buffer-substring (point-min) (point-at-eol))))))
+ p v nil tramp-actions-copy-out-of-band))))
;; Reset the transfer process properties.
(tramp-set-connection-property v "process-name" nil)
@@ -2666,7 +2541,10 @@ The method used must be an out-of-band method."
;; Handle KEEP-DATE argument.
(when (and keep-date (not copy-keep-date))
- (set-file-times newname (nth 5 (file-attributes filename))))
+ (set-file-times
+ newname
+ (tramp-compat-file-attribute-modification-time
+ (file-attributes filename))))
;; Set the mode.
(unless (and keep-date copy-keep-date)
@@ -2677,7 +2555,7 @@ The method used must be an out-of-band method."
(unless (eq op 'copy)
(if (file-regular-p filename)
(delete-file filename)
- (tramp-compat-delete-directory filename 'recursive))))))
+ (delete-directory filename 'recursive))))))
(defun tramp-sh-handle-make-directory (dir &optional parents)
"Like `make-directory' for Tramp files."
@@ -2717,51 +2595,16 @@ The method used must be an out-of-band method."
;; Dired.
-;; CCC: This does not seem to be enough. Something dies when
-;; we try and delete two directories under Tramp :/
-(defun tramp-sh-handle-dired-recursive-delete-directory (filename)
- "Recursively delete the directory given.
-This is like `dired-recursive-delete-directory' for Tramp files."
- (with-parsed-tramp-file-name filename nil
- ;; Run a shell command 'rm -r <localname>'.
- ;; Code shamelessly stolen from the dired implementation and, um, hacked :)
- (unless (file-exists-p filename)
- (tramp-error v 'file-error "No such directory: %s" filename))
- ;; Which is better, -r or -R? (-r works for me <daniel@danann.net>).
- (tramp-send-command
- v
- (format "rm -rf %s" (tramp-shell-quote-argument localname))
- ;; Don't read the output, do it explicitly.
- nil t)
- ;; Wait for the remote system to return to us...
- ;; This might take a while, allow it plenty of time.
- (tramp-wait-for-output (tramp-get-connection-process v) 120)
- ;; Make sure that it worked...
- (tramp-flush-file-property v (file-name-directory localname))
- (tramp-flush-directory-property v localname)
- (and (file-exists-p filename)
- (tramp-error
- v 'file-error "Failed to recursively delete %s" filename))))
+(defvar dired-compress-file-suffixes)
+(declare-function dired-remove-file "dired-aux")
-(defun tramp-sh-handle-dired-compress-file (file &rest _ok-flag)
+(defun tramp-sh-handle-dired-compress-file (file)
"Like `dired-compress-file' for Tramp files."
- ;; OK-FLAG is valid for XEmacs only, but not implemented.
;; Code stolen mainly from dired-aux.el.
(with-parsed-tramp-file-name file nil
(tramp-flush-file-property v localname)
(save-excursion
- (let ((suffixes
- (if (not (featurep 'xemacs))
- ;; Emacs case
- (symbol-value 'dired-compress-file-suffixes)
- ;; XEmacs has `dired-compression-method-alist', which is
- ;; transformed into `dired-compress-file-suffixes' structure.
- (mapcar
- (lambda (x)
- (list (concat (regexp-quote (nth 1 x)) "\\'")
- nil
- (mapconcat 'identity (nth 3 x) " ")))
- (symbol-value 'dired-compression-method-alist))))
+ (let ((suffixes dired-compress-file-suffixes)
suffix)
;; See if any suffix rule matches this file name.
(while suffixes
@@ -2779,8 +2622,7 @@ This is like `dired-recursive-delete-directory' for Tramp files."
(when (tramp-send-command-and-check
v (concat (nth 2 suffix) " "
(tramp-shell-quote-argument localname)))
- ;; `dired-remove-file' is not defined in XEmacs.
- (tramp-compat-funcall 'dired-remove-file file)
+ (dired-remove-file file)
(string-match (car suffix) file)
(concat (substring file 0 (match-beginning 0))))))
(t
@@ -2790,8 +2632,7 @@ This is like `dired-recursive-delete-directory' for Tramp files."
(when (tramp-send-command-and-check
v (concat "gzip -f "
(tramp-shell-quote-argument localname)))
- ;; `dired-remove-file' is not defined in XEmacs.
- (tramp-compat-funcall 'dired-remove-file file)
+ (dired-remove-file file)
(cond ((file-exists-p (concat file ".gz"))
(concat file ".gz"))
((file-exists-p (concat file ".z"))
@@ -2810,6 +2651,8 @@ This is like `dired-recursive-delete-directory' for Tramp files."
filename switches wildcard full-directory-p)
(when (stringp switches)
(setq switches (split-string switches)))
+ (when (tramp-get-ls-command-with-quoting-style v)
+ (setq switches (append switches '("--quoting-style=literal"))))
(when (and (member "--dired" switches)
(not (tramp-get-ls-command-with-dired v)))
(setq switches (delete "--dired" switches)))
@@ -2895,15 +2738,14 @@ This is like `dired-recursive-delete-directory' for Tramp files."
(unless
(string-match "color" (tramp-get-connection-property v "ls" ""))
(goto-char beg)
- (while (re-search-forward tramp-color-escape-sequence-regexp nil t)
+ (while
+ (re-search-forward tramp-display-escape-sequence-regexp nil t)
(replace-match "")))
;; Decode the output, it could be multibyte.
(decode-coding-region
beg (point-max)
- (or file-name-coding-system
- (and (boundp 'default-file-name-coding-system)
- (symbol-value 'default-file-name-coding-system))))
+ (or file-name-coding-system default-file-name-coding-system))
;; The inserted file could be from somewhere else.
(when (and (not wildcard) (not full-directory-p))
@@ -2930,7 +2772,7 @@ the result will be a local, non-Tramp, file name."
;; Unless NAME is absolute, concat DIR and NAME.
(unless (file-name-absolute-p name)
(setq name (concat (file-name-as-directory dir) name)))
- ;; If NAME is not a Tramp file, run the real handler.
+ ;; If connection is not established yet, run the real handler.
(if (not (tramp-connectable-p name))
(tramp-run-real-handler 'expand-file-name (list name nil))
;; Dissect NAME.
@@ -2966,13 +2808,10 @@ the result will be a local, non-Tramp, file name."
(while (string-match "//" localname)
(setq localname (replace-match "/" t t localname)))
;; No tilde characters in file name, do normal
- ;; `expand-file-name' (this does "/./" and "/../"). We bind
- ;; `directory-sep-char' here for XEmacs on Windows, which would
- ;; otherwise use backslash. `default-directory' is bound,
- ;; because on Windows there would be problems with UNC shares or
- ;; Cygwin mounts.
- (let ((directory-sep-char ?/)
- (default-directory (tramp-compat-temporary-file-directory)))
+ ;; `expand-file-name' (this does "/./" and "/../").
+ ;; `default-directory' is bound, because on Windows there would
+ ;; be problems with UNC shares or Cygwin mounts.
+ (let ((default-directory (tramp-compat-temporary-file-directory)))
(tramp-make-tramp-file-name
method user host
(tramp-drop-volume-letter
@@ -2984,7 +2823,7 @@ the result will be a local, non-Tramp, file name."
(defun tramp-process-sentinel (proc event)
"Flush file caches."
- (unless (memq (process-status proc) '(run open))
+ (unless (tramp-compat-process-live-p proc)
(let ((vec (tramp-get-connection-property proc "vector" nil)))
(when vec
(tramp-message vec 5 "Sentinel called: `%S' `%s'" proc event)
@@ -2997,7 +2836,12 @@ the result will be a local, non-Tramp, file name."
(defun tramp-sh-handle-start-file-process (name buffer program &rest args)
"Like `start-file-process' for Tramp files."
(with-parsed-tramp-file-name (expand-file-name default-directory) nil
- (let* (;; When PROGRAM matches "*sh", and the first arg is "-c",
+ (let* ((buffer
+ (if buffer
+ (get-buffer-create buffer)
+ ;; BUFFER can be nil. We use a temporary buffer.
+ (generate-new-buffer tramp-temp-buffer-name)))
+ ;; When PROGRAM matches "*sh", and the first arg is "-c",
;; it might be that the arguments exceed the command line
;; length. Therefore, we modify the command.
(heredoc (and (stringp program)
@@ -3060,9 +2904,6 @@ the result will be a local, non-Tramp, file name."
;; `eshell' and friends.
(tramp-current-connection nil))
- (unless buffer
- ;; BUFFER can be nil. We use a temporary buffer.
- (setq buffer (generate-new-buffer tramp-temp-buffer-name)))
(while (get-process name1)
;; NAME must be unique as process name.
(setq i (1+ i)
@@ -3099,7 +2940,7 @@ the result will be a local, non-Tramp, file name."
;; Send the command.
(tramp-send-command v command nil t) ; nooutput
;; Check, whether a pty is associated.
- (unless (tramp-compat-process-get
+ (unless (process-get
(tramp-get-connection-process v) 'remote-tty)
(tramp-error
v 'file-error
@@ -3109,7 +2950,7 @@ the result will be a local, non-Tramp, file name."
;; process. We ignore errors, because the process
;; could have finished already.
(ignore-errors
- (tramp-compat-set-process-query-on-exit-flag p t)
+ (set-process-query-on-exit-flag p t)
(set-marker (process-mark p) (point)))
;; Return process.
p))))
@@ -3241,12 +3082,7 @@ the result will be a local, non-Tramp, file name."
;; because the remote process could have changed them.
(when tmpinput (delete-file tmpinput))
- ;; `process-file-side-effects' has been introduced with GNU
- ;; Emacs 23.2. If set to nil, no remote file will be changed
- ;; by `program'. If it doesn't exist, we assume its default
- ;; value t.
- (unless (and (boundp 'process-file-side-effects)
- (not (symbol-value 'process-file-side-effects)))
+ (unless process-file-side-effects
(tramp-flush-directory-property v ""))
;; Return exit status.
@@ -3259,10 +3095,11 @@ the result will be a local, non-Tramp, file name."
(with-parsed-tramp-file-name filename nil
(unless (file-exists-p filename)
(tramp-error
- v 'file-error
+ v tramp-file-missing
"Cannot make local copy of non-existing file `%s'" filename))
- (let* ((size (nth 7 (file-attributes (file-truename filename))))
+ (let* ((size (tramp-compat-file-attribute-size
+ (file-attributes (file-truename filename))))
(rem-enc (tramp-get-inline-coding v "remote-encoding" size))
(loc-dec (tramp-get-inline-coding v "local-decoding" size))
(tmpfile (tramp-compat-make-temp-file filename)))
@@ -3272,7 +3109,7 @@ the result will be a local, non-Tramp, file name."
;; `copy-file' handles direct copy and out-of-band methods.
((or (tramp-local-host-p v)
(tramp-method-out-of-band-p v size))
- (copy-file filename tmpfile t t))
+ (copy-file filename tmpfile 'ok-if-already-exists 'keep-time))
;; Use inline encoding for file transfer.
(rem-enc
@@ -3333,30 +3170,6 @@ the result will be a local, non-Tramp, file name."
(run-hooks 'tramp-handle-file-local-copy-hook)
tmpfile)))
-;; This is needed for XEmacs only. Code stolen from files.el.
-(defun tramp-sh-handle-insert-file-contents-literally
- (filename &optional visit beg end replace)
- "Like `insert-file-contents-literally' for Tramp files."
- (let ((format-alist nil)
- (after-insert-file-functions nil)
- (coding-system-for-read 'no-conversion)
- (coding-system-for-write 'no-conversion)
- (find-buffer-file-type-function
- (if (fboundp 'find-buffer-file-type)
- (symbol-function 'find-buffer-file-type)
- nil))
- (inhibit-file-name-handlers
- '(epa-file-handler image-file-handler jka-compr-handler))
- (inhibit-file-name-operation 'insert-file-contents))
- (unwind-protect
- (progn
- (fset 'find-buffer-file-type (lambda (_filename) t))
- (insert-file-contents filename visit beg end replace))
- ;; Save exit.
- (if find-buffer-file-type-function
- (fset 'find-buffer-file-type find-buffer-file-type-function)
- (fmakunbound 'find-buffer-file-type)))))
-
;; CCC grok LOCKNAME
(defun tramp-sh-handle-write-region
(start end filename &optional append visit lockname confirm)
@@ -3373,14 +3186,15 @@ the result will be a local, non-Tramp, file name."
;; (error
;; "tramp-sh-handle-write-region: LOCKNAME must be nil or equal FILENAME"))
- ;; XEmacs takes a coding system as the seventh argument, not `confirm'.
- (when (and (not (featurep 'xemacs)) confirm (file-exists-p filename))
+ (when (and confirm (file-exists-p filename))
(unless (y-or-n-p (format "File %s exists; overwrite anyway? " filename))
(tramp-error v 'file-error "File not overwritten")))
- (let ((uid (or (nth 2 (tramp-compat-file-attributes filename 'integer))
+ (let ((uid (or (tramp-compat-file-attribute-user-id
+ (file-attributes filename 'integer))
(tramp-get-remote-uid v 'integer)))
- (gid (or (nth 3 (tramp-compat-file-attributes filename 'integer))
+ (gid (or (tramp-compat-file-attribute-group-id
+ (file-attributes filename 'integer))
(tramp-get-remote-gid v 'integer))))
(if (and (tramp-local-host-p v)
@@ -3438,9 +3252,7 @@ the result will be a local, non-Tramp, file name."
(signal (car err) (cdr err))))
;; Now, `last-coding-system-used' has the right value. Remember it.
- (when (boundp 'last-coding-system-used)
- (setq coding-system-used
- (symbol-value 'last-coding-system-used))))
+ (setq coding-system-used last-coding-system-used))
;; The permissions of the temporary file should be set. If
;; FILENAME does not exist (eq modes nil) it has been
@@ -3450,7 +3262,7 @@ the result will be a local, non-Tramp, file name."
(when modes
(set-file-modes
tmpfile
- (logior (or modes 0) (tramp-compat-octal-to-decimal "0400"))))
+ (logior (or modes 0) (string-to-number "0400" 8))))
;; This is a bit lengthy due to the different methods
;; possible for file transfer. First, we check whether the
@@ -3459,7 +3271,8 @@ the result will be a local, non-Tramp, file name."
;; specified. However, if the method _also_ specifies an
;; encoding function, then that is used for encoding the
;; contents of the tmp file.
- (let* ((size (nth 7 (file-attributes tmpfile)))
+ (let* ((size (tramp-compat-file-attribute-size
+ (file-attributes tmpfile)))
(rem-dec (tramp-get-inline-coding v "remote-decoding" size))
(loc-enc (tramp-get-inline-coding v "local-encoding" size)))
(cond
@@ -3590,14 +3403,14 @@ the result will be a local, non-Tramp, file name."
(let (last-coding-system-used (need-chown t))
;; Set file modification time.
(when (or (eq visit t) (stringp visit))
- (let ((file-attr (tramp-compat-file-attributes filename 'integer)))
+ (let ((file-attr (file-attributes filename 'integer)))
(set-visited-file-modtime
;; We must pass modtime explicitly, because FILENAME can
;; be different from (buffer-file-name), f.e. if
;; `file-precious-flag' is set.
- (nth 5 file-attr))
- (when (and (= (nth 2 file-attr) uid)
- (= (nth 3 file-attr) gid))
+ (tramp-compat-file-attribute-modification-time file-attr))
+ (when (and (= (tramp-compat-file-attribute-user-id file-attr) uid)
+ (= (tramp-compat-file-attribute-group-id file-attr) gid))
(setq need-chown nil))))
;; Set the ownership.
@@ -3625,7 +3438,7 @@ the result will be a local, non-Tramp, file name."
;; any other remote command.
(defun tramp-sh-handle-vc-registered (file)
"Like `vc-registered' for Tramp files."
- (tramp-compat-with-temp-message ""
+ (with-temp-message ""
(with-parsed-tramp-file-name file nil
(with-tramp-progress-reporter
v 3 (format-message "Checking `vc-registered' for %s" file)
@@ -3782,7 +3595,12 @@ Fall back to normal file name handler if no Tramp handler exists."
(concat "create,modify,move,moved_from,moved_to,move_self,"
"delete,delete_self,ignored"))
((memq 'attribute-change flags) "attrib,ignored"))
- sequence `(,command "-mq" "-e" ,events ,localname)))
+ sequence `(,command "-mq" "-e" ,events ,localname)
+ ;; Make events a list of symbols.
+ events
+ (mapcar
+ (lambda (x) (intern-soft (replace-regexp-in-string "_" "-" x)))
+ (split-string events "," 'omit))))
;; None.
(t (tramp-error
v 'file-notify-error
@@ -3803,15 +3621,15 @@ Fall back to normal file name handler if no Tramp handler exists."
(mapconcat 'identity sequence " "))
(tramp-message v 6 "Run `%s', %S" (mapconcat 'identity sequence " ") p)
(tramp-set-connection-property p "vector" v)
- ;; Needed for `tramp-sh-gvfs-monitor-dir-process-filter'.
- (tramp-compat-process-put p 'events events)
- (tramp-compat-process-put p 'watch-name localname)
- (tramp-compat-set-process-query-on-exit-flag p nil)
+ ;; Needed for process filter.
+ (process-put p 'events events)
+ (process-put p 'watch-name localname)
+ (set-process-query-on-exit-flag p nil)
(set-process-filter p filter)
;; There might be an error if the monitor is not supported.
;; Give the filter a chance to read the output.
(tramp-accept-process-output p 1)
- (unless (memq (process-status p) '(run open))
+ (unless (tramp-compat-process-live-p p)
(tramp-error
v 'file-notify-error "Monitoring not supported for `%s'" file-name))
p))))
@@ -3819,16 +3637,17 @@ Fall back to normal file name handler if no Tramp handler exists."
(defun tramp-sh-gvfs-monitor-dir-process-filter (proc string)
"Read output from \"gvfs-monitor-dir\" and add corresponding \
file-notify events."
- (let ((remote-prefix
+ (let ((events (process-get proc 'events))
+ (remote-prefix
(with-current-buffer (process-buffer proc)
(file-remote-p default-directory)))
- (rest-string (tramp-compat-process-get proc 'rest-string)))
+ (rest-string (process-get proc 'rest-string)))
(when rest-string
(tramp-message proc 10 "Previous string:\n%s" rest-string))
(tramp-message proc 6 "%S\n%s" proc string)
(setq string (concat rest-string string)
;; Attribute change is returned in unused wording.
- string (tramp-compat-replace-regexp-in-string
+ string (replace-regexp-in-string
"ATTRIB CHANGED" "ATTRIBUTE_CHANGED" string))
(when (string-match "Monitoring not supported" string)
(delete-process proc))
@@ -3845,59 +3664,65 @@ file-notify events."
(object
(list
proc
- (intern-soft
- (tramp-compat-replace-regexp-in-string
- "_" "-" (downcase (match-string 4 string))))
+ (list
+ (intern-soft
+ (replace-regexp-in-string
+ "_" "-" (downcase (match-string 4 string)))))
;; File names are returned as absolute paths. We must
;; add the remote prefix.
(concat remote-prefix file)
(when file1 (concat remote-prefix file1)))))
(setq string (replace-match "" nil nil string))
;; Remove watch when file or directory to be watched is deleted.
- (when (and (member (cadr object) '(moved deleted))
- (string-equal
- file (tramp-compat-process-get proc 'watch-name)))
+ (when (and (member (caadr object) '(moved deleted))
+ (string-equal file (process-get proc 'watch-name)))
(delete-process proc))
;; Usually, we would add an Emacs event now. Unfortunately,
;; `unread-command-events' does not accept several events at
- ;; once. Therefore, we apply the callback directly.
- (when (member (cadr object) (tramp-compat-process-get proc 'events))
- (tramp-compat-funcall 'file-notify-callback object))))
+ ;; once. Therefore, we apply the handler directly.
+ (when (member (caadr object) events)
+ (tramp-compat-funcall
+ 'file-notify-handle-event
+ `(file-notify ,object file-notify-callback)))))
;; Save rest of the string.
(when (zerop (length string)) (setq string nil))
(when string (tramp-message proc 10 "Rest string:\n%s" string))
- (tramp-compat-process-put proc 'rest-string string)))
+ (process-put proc 'rest-string string)))
(defun tramp-sh-inotifywait-process-filter (proc string)
"Read output from \"inotifywait\" and add corresponding file-notify events."
- (tramp-message proc 6 "%S\n%s" proc string)
- (dolist (line (split-string string "[\n\r]+" 'omit-nulls))
- ;; Check, whether there is a problem.
- (unless
- (string-match
- (concat "^[^[:blank:]]+"
- "[[:blank:]]+\\([^[:blank:]]+\\)+"
- "\\([[:blank:]]+\\([^\n\r]+\\)\\)?")
- line)
- (tramp-error proc 'file-notify-error "%s" line))
-
- (let ((object
- (list
- proc
- (mapcar
- (lambda (x)
- (intern-soft
- (tramp-compat-replace-regexp-in-string "_" "-" (downcase x))))
- (split-string (match-string 1 line) "," 'omit-nulls))
- (match-string 3 line))))
- ;; Remove watch when file or directory to be watched is deleted.
- (when (equal (cadr object) 'ignored)
- (delete-process proc))
- ;; Usually, we would add an Emacs event now. Unfortunately,
- ;; `unread-command-events' does not accept several events at
- ;; once. Therefore, we apply the callback directly.
- (tramp-compat-funcall 'file-notify-callback object))))
+ (let ((events (process-get proc 'events)))
+ (tramp-message proc 6 "%S\n%s" proc string)
+ (dolist (line (split-string string "[\n\r]+" 'omit))
+ ;; Check, whether there is a problem.
+ (unless
+ (string-match
+ (concat "^[^[:blank:]]+"
+ "[[:blank:]]+\\([^[:blank:]]+\\)+"
+ "\\([[:blank:]]+\\([^\n\r]+\\)\\)?")
+ line)
+ (tramp-error proc 'file-notify-error "%s" line))
+
+ (let ((object
+ (list
+ proc
+ (mapcar
+ (lambda (x)
+ (intern-soft
+ (replace-regexp-in-string "_" "-" (downcase x))))
+ (split-string (match-string 1 line) "," 'omit))
+ (match-string 3 line))))
+ ;; Remove watch when file or directory to be watched is deleted.
+ (when (member (caadr object) '(move-self delete-self ignored))
+ (delete-process proc))
+ ;; Usually, we would add an Emacs event now. Unfortunately,
+ ;; `unread-command-events' does not accept several events at
+ ;; once. Therefore, we apply the handler directly.
+ (when (member (caadr object) events)
+ (tramp-compat-funcall
+ 'file-notify-handle-event
+ `(file-notify ,object file-notify-callback)))))))
;;; Internal Functions:
@@ -3913,7 +3738,7 @@ Only send the definition if it has not already been done."
vec 5 (format-message "Sending script `%s'" name)
;; In bash, leading TABs like in `tramp-vc-registered-read-file-names'
;; could result in unwanted command expansion. Avoid this.
- (setq script (tramp-compat-replace-regexp-in-string
+ (setq script (replace-regexp-in-string
(make-string 1 ?\t) (make-string 8 ? ) script))
;; The script could contain a call of Perl. This is masked with `%s'.
(when (and (string-match "%s" script)
@@ -3986,8 +3811,7 @@ This function expects to be in the right *tramp* buffer."
(setq result (concat "\\" progname))))
(unless result
(when ignore-tilde
- ;; Remove all ~/foo directories from dirlist. In XEmacs,
- ;; `remove' is in CL, and we want to avoid CL dependencies.
+ ;; Remove all ~/foo directories from dirlist.
(let (newdl d)
(while dirlist
(setq d (car dirlist))
@@ -4107,7 +3931,8 @@ file exists and nonzero exit status otherwise."
;; $HISTFILE is set according to `tramp-histfile-override'.
(tramp-send-command
vec (format
- "exec env ENV='' %s PROMPT_COMMAND='' PS1=%s PS2='' PS3='' %s %s"
+ "exec env ENV=%s %s PROMPT_COMMAND='' PS1=%s PS2='' PS3='' %s %s"
+ (or (getenv-internal "ENV" tramp-remote-process-environment) "")
(if (stringp tramp-histfile-override)
(format "HISTFILE=%s"
(tramp-shell-quote-argument tramp-histfile-override))
@@ -4139,7 +3964,7 @@ file exists and nonzero exit status otherwise."
shell)
(setq shell
(with-tramp-connection-property vec "remote-shell"
- ;; CCC: "root" does not exist always, see QNAP 459.
+ ;; CCC: "root" does not exist always, see my QNAP TS-459.
;; Which check could we apply instead?
(tramp-send-command vec "echo ~root" t)
(if (or (string-match "^~root$" (buffer-string))
@@ -4243,41 +4068,32 @@ process to set up. VEC specifies the connection."
;; CCC this can't be the right way to do it. Hm.
(tramp-message vec 5 "Determining coding system")
(with-current-buffer (process-buffer proc)
- (if (featurep 'mule)
- ;; Use MULE to select the right EOL convention for
- ;; communicating with the process.
- (let ((cs (or (and (memq 'utf-8 (coding-system-list))
- (string-match "utf-?8" (tramp-get-remote-locale vec))
- (cons 'utf-8 'utf-8))
- (tramp-compat-funcall 'process-coding-system proc)
- (cons 'undecided 'undecided)))
- cs-decode cs-encode)
- (when (symbolp cs) (setq cs (cons cs cs)))
- (setq cs-decode (or (car cs) 'undecided)
- cs-encode (or (cdr cs) 'undecided))
- (setq cs-encode
- (tramp-compat-coding-system-change-eol-conversion
- cs-encode (if (string-match "^Darwin" uname) 'mac 'unix)))
- (tramp-send-command vec "echo foo ; echo bar" t)
- (goto-char (point-min))
- (when (search-forward "\r" nil t)
- (setq cs-decode (tramp-compat-coding-system-change-eol-conversion
- cs-decode 'dos)))
- ;; Special setting for macOS.
- (when (and (string-match "^Darwin" uname)
- (memq 'utf-8-hfs (coding-system-list)))
- (setq cs-decode 'utf-8-hfs
- cs-encode 'utf-8-hfs))
- (tramp-compat-funcall
- 'set-buffer-process-coding-system cs-decode cs-encode)
- (tramp-message
- vec 5 "Setting coding system to `%s' and `%s'" cs-decode cs-encode))
- ;; Look for ^M and do something useful if found.
- (when (search-forward "\r" nil t)
- ;; We have found a ^M but cannot frob the process coding
- ;; system because we're running on a non-MULE Emacs. Let's
- ;; try stty, instead.
- (tramp-send-command vec "stty -onlcr" t))))
+ ;; Use MULE to select the right EOL convention for communicating
+ ;; with the process.
+ (let ((cs (or (and (memq 'utf-8 (coding-system-list))
+ (string-match "utf-?8" (tramp-get-remote-locale vec))
+ (cons 'utf-8 'utf-8))
+ (process-coding-system proc)
+ (cons 'undecided 'undecided)))
+ cs-decode cs-encode)
+ (when (symbolp cs) (setq cs (cons cs cs)))
+ (setq cs-decode (or (car cs) 'undecided)
+ cs-encode (or (cdr cs) 'undecided)
+ cs-encode
+ (coding-system-change-eol-conversion
+ cs-encode (if (string-match "^Darwin" uname) 'mac 'unix)))
+ (tramp-send-command vec "echo foo ; echo bar" t)
+ (goto-char (point-min))
+ (when (search-forward "\r" nil t)
+ (setq cs-decode (coding-system-change-eol-conversion cs-decode 'dos)))
+ ;; Special setting for macOS.
+ (when (and (string-match "^Darwin" uname)
+ (memq 'utf-8-hfs (coding-system-list)))
+ (setq cs-decode 'utf-8-hfs
+ cs-encode 'utf-8-hfs))
+ (set-buffer-process-coding-system cs-decode cs-encode)
+ (tramp-message
+ vec 5 "Setting coding system to `%s' and `%s'" cs-decode cs-encode)))
(tramp-send-command vec "set +o vi +o emacs" t)
@@ -4332,7 +4148,7 @@ process to set up. VEC specifies the connection."
;; Set `remote-tty' process property.
(let ((tty (tramp-send-command-and-read vec "echo \\\"`tty`\\\"" 'noerror)))
(unless (zerop (length tty))
- (tramp-compat-process-put proc 'remote-tty tty)))
+ (process-put proc 'remote-tty tty)))
;; Dump stty settings in the traces.
(when (>= tramp-verbose 9)
@@ -4341,23 +4157,23 @@ process to set up. VEC specifies the connection."
;; Set the environment.
(tramp-message vec 5 "Setting default environment")
- (let ((env (append `(,(tramp-get-remote-locale vec))
- (copy-sequence tramp-remote-process-environment)))
- unset vars item)
- (while env
- (setq item (tramp-compat-split-string (car env) "="))
- (setcdr item (mapconcat 'identity (cdr item) "="))
- (if (and (stringp (cdr item)) (not (string-equal (cdr item) "")))
- (push (format "%s %s" (car item) (cdr item)) vars)
- (push (car item) unset))
- (setq env (cdr env)))
+ (let (unset vars)
+ (dolist (item (reverse
+ (append `(,(tramp-get-remote-locale vec))
+ (copy-sequence tramp-remote-process-environment))))
+ (setq item (split-string item "=" 'omit))
+ (setcdr item (mapconcat 'identity (cdr item) "="))
+ (if (and (stringp (cdr item)) (not (string-equal (cdr item) "")))
+ (push (format "%s %s" (car item) (cdr item)) vars)
+ (push (car item) unset)))
(when vars
(tramp-send-command
vec
- (format "while read var val; do export $var=$val; done <<'%s'\n%s\n%s"
- tramp-end-of-heredoc
- (mapconcat 'identity vars "\n")
- tramp-end-of-heredoc)
+ (format
+ "while read var val; do export $var=\"$val\"; done <<'%s'\n%s\n%s"
+ tramp-end-of-heredoc
+ (mapconcat 'identity vars "\n")
+ tramp-end-of-heredoc)
t))
(when unset
(tramp-send-command
@@ -4535,8 +4351,7 @@ Goes through the list `tramp-local-coding-commands' and
value
(format-spec-make
?t
- (tramp-file-name-handler
- 'file-remote-p tmpfile 'localname)))))
+ (file-remote-p tmpfile 'localname)))))
(tramp-maybe-send-script vec value name)
(setq rem-dec name)))
(tramp-message
@@ -4657,8 +4472,7 @@ Goes through the list `tramp-inline-compress-commands'."
vec 2 "Couldn't find an inline transfer compress command")))))
(defun tramp-compute-multi-hops (vec)
- "Expands VEC according to `tramp-default-proxies-alist'.
-Gateway hops are already opened."
+ "Expands VEC according to `tramp-default-proxies-alist'."
(let ((target-alist `(,vec))
(hops (or (tramp-file-name-hop vec) ""))
(item vec)
@@ -4715,32 +4529,6 @@ Gateway hops are already opened."
;; Start next search.
(setq choices tramp-default-proxies-alist)))))
- ;; Handle gateways.
- (when (and (boundp 'tramp-gw-tunnel-method) (boundp 'tramp-gw-socks-method)
- (string-match
- (format
- "^\\(%s\\|%s\\)$" tramp-gw-tunnel-method tramp-gw-socks-method)
- (tramp-file-name-method (car target-alist))))
- (let ((gw (pop target-alist))
- (hop (pop target-alist)))
- ;; Is the method prepared for gateways?
- (unless (tramp-file-name-port hop)
- (tramp-error
- vec 'file-error
- "Connection `%s' is not supported for gateway access." hop))
- ;; Open the gateway connection.
- (push
- (vector
- (tramp-file-name-method hop) (tramp-file-name-user hop)
- (tramp-compat-funcall 'tramp-gw-open-connection vec gw hop) nil nil)
- target-alist)
- ;; For the password prompt, we need the correct values.
- ;; Therefore, we must remember the gateway vector. But we
- ;; cannot do it as connection property, because it shouldn't
- ;; be persistent. And we have no started process yet either.
- (let ((tramp-verbose 0))
- (tramp-set-file-property (car target-alist) "" "gateway" hop))))
-
;; Foreign and out-of-band methods are not supported for multi-hops.
(when (cdr target-alist)
(setq choices target-alist)
@@ -4830,7 +4618,7 @@ connection if a previous connection has died for some reason."
;; If Tramp opens the same connection within a short time frame,
;; there is a problem. We shall signal this.
- (unless (or (and p (processp p) (memq (process-status p) '(run open)))
+ (unless (or (tramp-compat-process-live-p p)
(not (equal (butlast (append vec nil) 2)
(car tramp-current-connection)))
(> (tramp-time-diff
@@ -4851,9 +4639,9 @@ connection if a previous connection has died for some reason."
(tramp-get-connection-property
p "last-cmd-time" '(0 0 0)))
60)
- p (processp p) (memq (process-status p) '(run open)))
+ (tramp-compat-process-live-p p))
(tramp-send-command vec "echo are you awake" t t)
- (unless (and (memq (process-status p) '(run open))
+ (unless (and (tramp-compat-process-live-p p)
(tramp-wait-for-output p 10))
;; The error will be caught locally.
(tramp-error vec 'file-error "Awake did fail")))
@@ -4863,9 +4651,10 @@ connection if a previous connection has died for some reason."
;; New connection must be opened.
(condition-case err
- (unless (and p (processp p) (memq (process-status p) '(run open)))
+ (unless (tramp-compat-process-live-p p)
;; If `non-essential' is non-nil, don't reopen a new connection.
+ ;; This variable has been introduced with Emacs 24.1.
(when (and (boundp 'non-essential) (symbol-value 'non-essential))
(throw 'non-essential 'non-essential))
@@ -4903,6 +4692,9 @@ connection if a previous connection has died for some reason."
(options (tramp-ssh-controlmaster-options vec))
(process-connection-type tramp-process-connection-type)
(process-adaptive-read-buffering nil)
+ ;; There are unfortunate settings for "cmdproxy" on
+ ;; W32 systems.
+ (process-coding-system-alist nil)
(coding-system-for-read nil)
;; This must be done in order to avoid our file
;; name handler.
@@ -4920,7 +4712,7 @@ connection if a previous connection has died for some reason."
;; Set sentinel and query flag.
(tramp-set-connection-property p "vector" vec)
(set-process-sentinel p 'tramp-process-sentinel)
- (tramp-compat-set-process-query-on-exit-flag p nil)
+ (set-process-query-on-exit-flag p nil)
(setq tramp-current-connection
(cons (butlast (append vec nil) 2) (current-time))
tramp-current-host (system-name))
@@ -4951,13 +4743,6 @@ connection if a previous connection has died for some reason."
(connection-timeout
(tramp-get-method-parameter
hop 'tramp-connection-timeout))
- (gw-args
- (tramp-get-method-parameter hop 'tramp-gw-args))
- (gw (let ((tramp-verbose 0))
- (tramp-get-file-property hop "" "gateway" nil)))
- (g-method (and gw (tramp-file-name-method gw)))
- (g-user (and gw (tramp-file-name-user gw)))
- (g-host (and gw (tramp-file-name-real-host gw)))
(command login-program)
;; We don't create the temporary file. In
;; fact, it is just a prefix for the
@@ -4981,12 +4766,6 @@ connection if a previous connection has died for some reason."
(when (and process-name async-args)
(setq login-args (append async-args login-args)))
- ;; Add gateway arguments if necessary.
- (when gw
- (tramp-set-connection-property p "gateway" t)
- (when gw-args
- (setq login-args (append gw-args login-args))))
-
;; Check for port number. Until now, there's no
;; need for handling like method, user, host.
(when (string-match tramp-host-with-port-regexp l-host)
@@ -4999,11 +4778,10 @@ connection if a previous connection has died for some reason."
(setq r-shell t)))
;; Set variables for computing the prompt for
- ;; reading password. They can also be derived
- ;; from a gateway.
- (setq tramp-current-method (or g-method l-method)
- tramp-current-user (or g-user l-user)
- tramp-current-host (or g-host l-host))
+ ;; reading password.
+ (setq tramp-current-method l-method
+ tramp-current-user l-user
+ tramp-current-host l-host)
;; Add login environment.
(when login-env
@@ -5054,7 +4832,10 @@ connection if a previous connection has died for some reason."
(tramp-message vec 3 "Sending command `%s'" command)
(tramp-send-command vec command t t)
(tramp-process-actions
- p vec pos tramp-actions-before-shell
+ p vec
+ (min
+ pos (with-current-buffer (process-buffer p) (point-max)))
+ tramp-actions-before-shell
(or connection-timeout tramp-connection-timeout))
(tramp-message
vec 3 "Found remote shell prompt on `%s'" l-host))
@@ -5062,6 +4843,9 @@ connection if a previous connection has died for some reason."
(setq options ""
target-alist (cdr target-alist)))
+ ;; Set connection-local variables.
+ (tramp-set-connection-local-variables vec)
+
;; Make initial shell settings.
(tramp-open-connection-setup-interactive-shell p vec)
@@ -5109,7 +4893,12 @@ function waits for output unless NOOUTPUT is set."
(with-current-buffer (process-buffer proc)
(let* (;; Initially, `tramp-end-of-output' is "#$ ". There might
;; be leading escape sequences, which must be ignored.
- (regexp (format "[^#$\n]*%s\r?$" (regexp-quote tramp-end-of-output)))
+ ;; Busyboxes built with the EDITING_ASK_TERMINAL config
+ ;; option send also escape sequences, which must be
+ ;; ignored.
+ (regexp (format "[^#$\n]*%s\\(%s\\)?\r?$"
+ (regexp-quote tramp-end-of-output)
+ tramp-device-escape-sequence-regexp))
;; Sometimes, the commands do not return a newline but a
;; null byte before the shell prompt, for example "git
;; ls-files -c -z ...".
@@ -5212,18 +5001,19 @@ Return ATTR."
(when attr
;; Remove color escape sequences from symlink.
(when (stringp (car attr))
- (while (string-match tramp-color-escape-sequence-regexp (car attr))
+ (while (string-match tramp-display-escape-sequence-regexp (car attr))
(setcar attr (replace-match "" nil nil (car attr)))))
- ;; Convert uid and gid. Use -1 as indication of unusable value.
+ ;; Convert uid and gid. Use `tramp-unknown-id-integer' as
+ ;; indication of unusable value.
(when (and (numberp (nth 2 attr)) (< (nth 2 attr) 0))
- (setcar (nthcdr 2 attr) -1))
+ (setcar (nthcdr 2 attr) tramp-unknown-id-integer))
(when (and (floatp (nth 2 attr))
- (<= (nth 2 attr) (tramp-compat-most-positive-fixnum)))
+ (<= (nth 2 attr) most-positive-fixnum))
(setcar (nthcdr 2 attr) (round (nth 2 attr))))
(when (and (numberp (nth 3 attr)) (< (nth 3 attr) 0))
- (setcar (nthcdr 3 attr) -1))
+ (setcar (nthcdr 3 attr) tramp-unknown-id-integer))
(when (and (floatp (nth 3 attr))
- (<= (nth 3 attr) (tramp-compat-most-positive-fixnum)))
+ (<= (nth 3 attr) most-positive-fixnum))
(setcar (nthcdr 3 attr) (round (nth 3 attr))))
;; Convert last access time.
(unless (listp (nth 4 attr))
@@ -5244,7 +5034,7 @@ Return ATTR."
(when (< (nth 7 attr) 0)
(setcar (nthcdr 7 attr) -1))
(when (and (floatp (nth 7 attr))
- (<= (nth 7 attr) (tramp-compat-most-positive-fixnum)))
+ (<= (nth 7 attr) most-positive-fixnum))
(setcar (nthcdr 7 attr) (round (nth 7 attr))))
;; Convert file mode bits to string.
(unless (stringp (nth 8 attr))
@@ -5296,7 +5086,8 @@ Return ATTR."
(let ((method (tramp-file-name-method vec))
(user (tramp-file-name-user vec))
(host (tramp-file-name-real-host vec))
- (localname (tramp-file-name-localname vec)))
+ (localname
+ (directory-file-name (tramp-file-name-unquote-localname vec))))
(when (string-match tramp-ipv6-regexp host)
(setq host (format "[%s]" host)))
(unless (string-match "ftp$" method)
@@ -5305,8 +5096,8 @@ Return ATTR."
((tramp-get-method-parameter vec 'tramp-remote-copy-program)
localname)
((not (zerop (length user)))
- (shell-quote-argument (format "%s@%s:%s" user host localname)))
- (t (shell-quote-argument (format "%s:%s" host localname))))))
+ (format "%s@%s:%s" user host (shell-quote-argument localname)))
+ (t (format "%s:%s" host (shell-quote-argument localname))))))
(defun tramp-method-out-of-band-p (vec size)
"Return t if this is an out-of-band method, nil otherwise."
@@ -5324,6 +5115,8 @@ Return ATTR."
;; Variables local to connection.
(defun tramp-get-remote-path (vec)
+ "Compile list of remote directories for $PATH.
+Nonexistent directories are removed from spec."
(with-tramp-connection-property
;; When `tramp-own-remote-path' is in `tramp-remote-path', we
;; cache the result for the session only. Otherwise, the result
@@ -5376,7 +5169,7 @@ Return ATTR."
(when elt1
(setcdr elt1
(append
- (tramp-compat-split-string (or default-remote-path "") ":")
+ (split-string (or default-remote-path "") ":" 'omit)
(cdr elt1)))
(setq remote-path (delq 'tramp-default-remote-path remote-path)))
@@ -5384,7 +5177,7 @@ Return ATTR."
(when elt2
(setcdr elt2
(append
- (tramp-compat-split-string (or own-remote-path "") ":")
+ (split-string (or own-remote-path "") ":" 'omit)
(cdr elt2)))
(setq remote-path (delq 'tramp-own-remote-path remote-path)))
@@ -5412,6 +5205,7 @@ Return ATTR."
remote-path)))))
(defun tramp-get-remote-locale (vec)
+ "Determine remote locale, supporting UTF8 if possible."
(with-tramp-connection-property vec "locale"
(tramp-send-command vec "locale -a")
(let ((candidates '("en_US.utf8" "C.utf8" "en_US.UTF-8"))
@@ -5428,6 +5222,7 @@ Return ATTR."
(format "LC_ALL=%s" (or locale "C")))))
(defun tramp-get-ls-command (vec)
+ "Determine remote `ls' command."
(with-tramp-connection-property vec "ls"
(tramp-message vec 5 "Finding a suitable `ls' command")
(or
@@ -5453,6 +5248,7 @@ Return ATTR."
(tramp-error vec 'file-error "Couldn't find a proper `ls' command"))))
(defun tramp-get-ls-command-with-dired (vec)
+ "Check, whether the remote `ls' command supports the --dired option."
(save-match-data
(with-tramp-connection-property vec "ls-dired"
(tramp-message vec 5 "Checking, whether `ls --dired' works")
@@ -5463,6 +5259,7 @@ Return ATTR."
vec (format "%s --dired -al /dev/null" (tramp-get-ls-command vec))))))
(defun tramp-get-ls-command-with-quoting-style (vec)
+ "Check, whether the remote `ls' command supports the --quoting-style option."
(save-match-data
(with-tramp-connection-property vec "ls-quoting-style"
(tramp-message vec 5 "Checking, whether `ls --quoting-style=shell' works")
@@ -5471,6 +5268,7 @@ Return ATTR."
(tramp-get-ls-command vec))))))
(defun tramp-get-ls-command-with-w-option (vec)
+ "Check, whether the remote `ls' command supports the -w option."
(save-match-data
(with-tramp-connection-property vec "ls-w-option"
(tramp-message vec 5 "Checking, whether `ls -w' works")
@@ -5481,6 +5279,7 @@ Return ATTR."
vec (format "%s -alw" (tramp-get-ls-command vec))))))
(defun tramp-get-test-command (vec)
+ "Determine remote `test' command."
(with-tramp-connection-property vec "test"
(tramp-message vec 5 "Finding a suitable `test' command")
(if (tramp-send-command-and-check vec "test 0")
@@ -5488,6 +5287,7 @@ Return ATTR."
(tramp-find-executable vec "test" (tramp-get-remote-path vec)))))
(defun tramp-get-test-nt-command (vec)
+ "Check, whether the remote `test' command supports the -nt option."
;; Does `test A -nt B' work? Use abominable `find' construct if it
;; doesn't. BSD/OS 4.0 wants the parentheses around the command,
;; for otherwise the shell crashes.
@@ -5509,33 +5309,41 @@ Return ATTR."
"tramp_test_nt %s %s"))))
(defun tramp-get-file-exists-command (vec)
+ "Determine remote command for file existing check."
(with-tramp-connection-property vec "file-exists"
(tramp-message vec 5 "Finding command to check if file exists")
(tramp-find-file-exists-command vec)))
(defun tramp-get-remote-ln (vec)
+ "Determine remote `ln' command."
(with-tramp-connection-property vec "ln"
(tramp-message vec 5 "Finding a suitable `ln' command")
(tramp-find-executable vec "ln" (tramp-get-remote-path vec))))
(defun tramp-get-remote-perl (vec)
+ "Determine remote `perl' command."
(with-tramp-connection-property vec "perl"
(tramp-message vec 5 "Finding a suitable `perl' command")
(let ((result
(or (tramp-find-executable vec "perl5" (tramp-get-remote-path vec))
- (tramp-find-executable
- vec "perl" (tramp-get-remote-path vec)))))
+ (tramp-find-executable vec "perl" (tramp-get-remote-path vec)))))
+ ;; Perform a basic check.
+ (and result
+ (null (tramp-send-command-and-check
+ vec (format "%s -e 'print \"Hello\n\";'" result)))
+ (setq result nil))
;; We must check also for some Perl modules.
(when result
(with-tramp-connection-property vec "perl-file-spec"
- (tramp-send-command-and-check
- vec (format "%s -e 'use File::Spec;'" result)))
+ (tramp-send-command-and-check
+ vec (format "%s -e 'use File::Spec;'" result)))
(with-tramp-connection-property vec "perl-cwd-realpath"
- (tramp-send-command-and-check
- vec (format "%s -e 'use Cwd \"realpath\";'" result))))
+ (tramp-send-command-and-check
+ vec (format "%s -e 'use Cwd \"realpath\";'" result))))
result)))
(defun tramp-get-remote-stat (vec)
+ "Determine remote `stat' command."
(with-tramp-connection-property vec "stat"
(tramp-message vec 5 "Finding a suitable `stat' command")
(let ((result (tramp-find-executable
@@ -5556,6 +5364,7 @@ Return ATTR."
result)))
(defun tramp-get-remote-readlink (vec)
+ "Determine remote `readlink' command."
(with-tramp-connection-property vec "readlink"
(tramp-message vec 5 "Finding a suitable `readlink' command")
(let ((result (tramp-find-executable
@@ -5566,11 +5375,13 @@ Return ATTR."
result))))
(defun tramp-get-remote-trash (vec)
+ "Determine remote `trash' command."
(with-tramp-connection-property vec "trash"
(tramp-message vec 5 "Finding a suitable `trash' command")
(tramp-find-executable vec "trash" (tramp-get-remote-path vec))))
(defun tramp-get-remote-touch (vec)
+ "Determine remote `touch' command."
(with-tramp-connection-property vec "touch"
(tramp-message vec 5 "Finding a suitable `touch' command")
(let ((result (tramp-find-executable
@@ -5590,22 +5401,25 @@ Return ATTR."
"%s -t %s %s"
result
(format-time-string "%Y%m%d%H%M.%S")
- (tramp-file-name-handler 'file-remote-p tmpfile 'localname))))
+ (file-remote-p tmpfile 'localname))))
(delete-file tmpfile))
result)))
(defun tramp-get-remote-gvfs-monitor-dir (vec)
+ "Determine remote `gvfs-monitor-dir' command."
(with-tramp-connection-property vec "gvfs-monitor-dir"
(tramp-message vec 5 "Finding a suitable `gvfs-monitor-dir' command")
(tramp-find-executable
vec "gvfs-monitor-dir" (tramp-get-remote-path vec) t t)))
(defun tramp-get-remote-inotifywait (vec)
+ "Determine remote `inotifywait' command."
(with-tramp-connection-property vec "inotifywait"
(tramp-message vec 5 "Finding a suitable `inotifywait' command")
(tramp-find-executable vec "inotifywait" (tramp-get-remote-path vec) t t)))
(defun tramp-get-remote-id (vec)
+ "Determine remote `id' command."
(with-tramp-connection-property vec "id"
(tramp-message vec 5 "Finding POSIX `id' command")
(catch 'id-found
@@ -5619,6 +5433,7 @@ Return ATTR."
(setq dl (cdr dl))))))))
(defun tramp-get-remote-uid-with-id (vec id-format)
+ "Implement `tramp-get-remote-uid' for Tramp files using `id'."
(tramp-send-command-and-read
vec
(format "%s -u%s %s"
@@ -5628,6 +5443,7 @@ Return ATTR."
"" "| sed -e s/^/\\\"/ -e s/\\$/\\\"/"))))
(defun tramp-get-remote-uid-with-perl (vec id-format)
+ "Implement `tramp-get-remote-uid' for Tramp files using a Perl script."
(tramp-send-command-and-read
vec
(format "%s -le '%s'"
@@ -5637,6 +5453,7 @@ Return ATTR."
"print \"\\\"\", scalar getpwuid($>), \"\\\"\""))))
(defun tramp-get-remote-python (vec)
+ "Determine remote `python' command."
(with-tramp-connection-property vec "python"
(tramp-message vec 5 "Finding a suitable `python' command")
(or (tramp-find-executable vec "python" (tramp-get-remote-path vec))
@@ -5644,6 +5461,7 @@ Return ATTR."
(tramp-find-executable vec "python3" (tramp-get-remote-path vec)))))
(defun tramp-get-remote-uid-with-python (vec id-format)
+ "Implement `tramp-get-remote-uid' for Tramp files using `python'."
(tramp-send-command-and-read
vec
(format "%s -c \"%s\""
@@ -5653,6 +5471,8 @@ Return ATTR."
"import os, pwd; print ('\\\"' + pwd.getpwuid(os.getuid())[0] + '\\\"')"))))
(defun tramp-get-remote-uid (vec id-format)
+ "The uid of the remote connection VEC, in ID-FORMAT.
+ID-FORMAT valid values are `string' and `integer'."
(with-tramp-connection-property vec (format "uid-%s" id-format)
(let ((res
(ignore-errors
@@ -5665,11 +5485,14 @@ Return ATTR."
(tramp-get-remote-uid-with-python vec id-format))))))
;; Ensure there is a valid result.
(cond
- ((and (equal id-format 'integer) (not (integerp res))) -1)
- ((and (equal id-format 'string) (not (stringp res))) "UNKNOWN")
+ ((and (equal id-format 'integer) (not (integerp res)))
+ tramp-unknown-id-integer)
+ ((and (equal id-format 'string) (not (stringp res)))
+ tramp-unknown-id-string)
(t res)))))
(defun tramp-get-remote-gid-with-id (vec id-format)
+ "Implement `tramp-get-remote-gid' for Tramp files using `id'."
(tramp-send-command-and-read
vec
(format "%s -g%s %s"
@@ -5679,6 +5502,7 @@ Return ATTR."
"" "| sed -e s/^/\\\"/ -e s/\\$/\\\"/"))))
(defun tramp-get-remote-gid-with-perl (vec id-format)
+ "Implement `tramp-get-remote-gid' for Tramp files using a Perl script."
(tramp-send-command-and-read
vec
(format "%s -le '%s'"
@@ -5688,6 +5512,7 @@ Return ATTR."
"print \"\\\"\", scalar getgrgid($)), \"\\\"\""))))
(defun tramp-get-remote-gid-with-python (vec id-format)
+ "Implement `tramp-get-remote-gid' for Tramp files using `python'."
(tramp-send-command-and-read
vec
(format "%s -c \"%s\""
@@ -5697,6 +5522,8 @@ Return ATTR."
"import os, grp; print ('\\\"' + grp.getgrgid(os.getgid())[0] + '\\\"')"))))
(defun tramp-get-remote-gid (vec id-format)
+ "The gid of the remote connection VEC, in ID-FORMAT.
+ID-FORMAT valid values are `string' and `integer'."
(with-tramp-connection-property vec (format "gid-%s" id-format)
(let ((res
(ignore-errors
@@ -5709,11 +5536,14 @@ Return ATTR."
(tramp-get-remote-gid-with-python vec id-format))))))
;; Ensure there is a valid result.
(cond
- ((and (equal id-format 'integer) (not (integerp res))) -1)
- ((and (equal id-format 'string) (not (stringp res))) "UNKNOWN")
+ ((and (equal id-format 'integer) (not (integerp res)))
+ tramp-unknown-id-integer)
+ ((and (equal id-format 'string) (not (stringp res)))
+ tramp-unknown-id-string)
(t res)))))
(defun tramp-get-env-with-u-option (vec)
+ "Check, whether the remote `env' command supports the -u option."
(with-tramp-connection-property vec "env-u-option"
(tramp-message vec 5 "Checking, whether `env -u' works")
;; Option "-u" is a GNU extension.
@@ -5776,18 +5606,14 @@ function cell is returned to be applied on a buffer."
`(lambda (beg end)
(,coding beg end)
(let ((coding-system-for-write 'binary)
- (coding-system-for-read 'binary)
- (default-directory
- (tramp-compat-temporary-file-directory)))
+ (coding-system-for-read 'binary))
(apply
'tramp-call-process-region ,vec (point-min) (point-max)
(car (split-string ,compress)) t t nil
(cdr (split-string ,compress)))))
`(lambda (beg end)
(let ((coding-system-for-write 'binary)
- (coding-system-for-read 'binary)
- (default-directory
- (tramp-compat-temporary-file-directory)))
+ (coding-system-for-read 'binary))
(apply
'tramp-call-process-region ,vec beg end
(car (split-string ,compress)) t t nil
@@ -5835,14 +5661,18 @@ function cell is returned to be applied on a buffer."
;; * Don't use globbing for directories with many files, as this is
;; likely to produce long command lines, and some shells choke on
;; long command lines.
+;;
;; * Don't search for perl5 and perl. Instead, only search for perl and
;; then look if it's the right version (with `perl -v').
+;;
;; * When editing a remote CVS controlled file as a different user, VC
;; gets confused about the file locking status. Try to find out why
;; the workaround doesn't work.
+;;
;; * Allow out-of-band methods as _last_ multi-hop. Open a connection
;; until the last but one hop via `start-file-process'. Apply it
;; also for ftp and smb.
+;;
;; * WIBNI if we had a command "trampclient"? If I was editing in
;; some shell with root privileges, it would be nice if I could
;; just call
@@ -5864,21 +5694,60 @@ function cell is returned to be applied on a buffer."
;; reasonably unproblematic. And maybe trampclient should have some
;; way of passing credentials, like by using an SSL socket or
;; something. (David Kastrup)
+;;
;; * Reconnect directly to a compliant shell without first going
;; through the user's default shell. (Pete Forman)
+;;
;; * How can I interrupt the remote process with a signal
;; (interrupt-process seems not to work)? (Markus Triska)
+;;
;; * Avoid the local shell entirely for starting remote processes. If
;; so, I think even a signal, when delivered directly to the local
;; SSH instance, would correctly be propagated to the remote process
;; automatically; possibly SSH would have to be started with
;; "-t". (Markus Triska)
+;;
;; * It makes me wonder if tramp couldn't fall back to ssh when scp
;; isn't on the remote host. (Mark A. Hershberger)
+;;
;; * Use lsh instead of ssh. (Alfred M. Szmidt)
+;;
;; * Optimize out-of-band copying when both methods are scp-like (not
;; rsync).
+;;
;; * Keep a second connection open for out-of-band methods like scp or
;; rsync.
+;;
+;; * Implement completion for "/method:user@host:~<abc> TAB".
+;;
+;; * I think you could get the best of both worlds by using an
+;; approach similar to Tramp but running a little tramp-daemon on
+;; the other end, such that we can use a more efficient
+;; communication protocol (e.g. when saving a file we could locally
+;; diff it against the last version (of which the remote daemon
+;; would also keep a copy), and then only send the diff).
+;;
+;; This said, even using such a daemon it might be difficult to get
+;; good performance: part of the problem is the number of
+;; round-trips. E.g. when saving a file we have to check if the
+;; file was modified in the mean time and whether saving into a new
+;; inode would change the owner (etc...), which each require a
+;; round-trip. To get rid of these round-trips, we'd have to
+;; shortcut this code and delegate the higher-level "save file"
+;; operation to the remote server, which then has to perform those
+;; tasks but still obeying the locally set customizations about how
+;; to do each one of those tasks.
+;;
+;; We could either put higher-level ops in there (like
+;; `save-buffer'), which implies replicating the whole `save-buffer'
+;; behavior, which is a lot of work and likely to be not 100%
+;; faithful.
+;;
+;; Or we could introduce new low-level ops that are asynchronous,
+;; and then rewrite save-buffer to use them. IOW save-buffer would
+;; start with a bunch of calls like `start-getting-file-attributes'
+;; which could immediately be passed on to the remote side, and
+;; later on checks the return value of those calls as and when
+;; needed. (Stefan Monnier)
;;; tramp-sh.el ends here
diff --git a/lisp/net/tramp-smb.el b/lisp/net/tramp-smb.el
index 509e2e388b8..70b72d82f54 100644
--- a/lisp/net/tramp-smb.el
+++ b/lisp/net/tramp-smb.el
@@ -49,7 +49,9 @@
;; This is just a guess. We don't know whether the share "C$"
;; is available for public use, and whether the user has write
;; access.
- (tramp-tmpdir "/C$/Temp"))))
+ (tramp-tmpdir "/C$/Temp")
+ ;; Another guess. We might implement a better check later on.
+ (tramp-case-insensitive t))))
;; Add a default for `tramp-default-method-alist'. Rule: If there is
;; a domain in USER, it must be the SMB method.
@@ -74,14 +76,16 @@
(defcustom tramp-smb-program "smbclient"
"Name of SMB client to run."
:group 'tramp
- :type 'string)
+ :type 'string
+ :require 'tramp)
;;;###tramp-autoload
(defcustom tramp-smb-acl-program "smbcacls"
"Name of SMB acls to run."
:group 'tramp
:type 'string
- :version "24.4")
+ :version "24.4"
+ :require 'tramp)
;;;###tramp-autoload
(defcustom tramp-smb-conf "/dev/null"
@@ -89,7 +93,8 @@
If it is nil, no smb.conf will be added to the `tramp-smb-program'
call, letting the SMB client use the default one."
:group 'tramp
- :type '(choice (const nil) (file :must-match t)))
+ :type '(choice (const nil) (file :must-match t))
+ :require 'tramp)
(defvar tramp-smb-version nil
"Version string of the SMB client.")
@@ -129,7 +134,8 @@ call, letting the SMB client use the default one."
"ERRnosuchshare"
;; Windows 4.0 (Windows NT), Windows 5.0 (Windows 2000),
;; Windows 5.1 (Windows XP), Windows 5.2 (Windows Server 2003),
- ;; Windows 6.0 (Windows Vista), Windows 6.1 (Windows 7).
+ ;; Windows 6.0 (Windows Vista), Windows 6.1 (Windows 7),
+ ;; Windows 6.3 (Windows Server 2012, Windows 10).
"NT_STATUS_ACCESS_DENIED"
"NT_STATUS_ACCOUNT_LOCKED_OUT"
"NT_STATUS_BAD_NETWORK_NAME"
@@ -224,7 +230,6 @@ See `tramp-actions-before-shell' for more info.")
(directory-files . tramp-smb-handle-directory-files)
(directory-files-and-attributes
. tramp-handle-directory-files-and-attributes)
- (dired-call-process . ignore)
(dired-compress-file . ignore)
(dired-uncache . tramp-handle-dired-uncache)
(expand-file-name . tramp-smb-handle-expand-file-name)
@@ -240,6 +245,7 @@ See `tramp-actions-before-shell' for more info.")
(file-modes . tramp-handle-file-modes)
(file-name-all-completions . tramp-smb-handle-file-name-all-completions)
(file-name-as-directory . tramp-handle-file-name-as-directory)
+ (file-name-case-insensitive-p . tramp-handle-file-name-case-insensitive-p)
(file-name-completion . tramp-handle-file-name-completion)
(file-name-directory . tramp-handle-file-name-directory)
(file-name-nondirectory . tramp-handle-file-name-nondirectory)
@@ -265,6 +271,7 @@ See `tramp-actions-before-shell' for more info.")
(make-auto-save-file-name . tramp-handle-make-auto-save-file-name)
(make-directory . tramp-smb-handle-make-directory)
(make-directory-internal . tramp-smb-handle-make-directory-internal)
+ (make-nearby-temp-file . tramp-handle-make-nearby-temp-file)
(make-symbolic-link . tramp-smb-handle-make-symbolic-link)
(process-file . tramp-smb-handle-process-file)
(rename-file . tramp-smb-handle-rename-file)
@@ -276,7 +283,8 @@ See `tramp-actions-before-shell' for more info.")
(shell-command . tramp-handle-shell-command)
(start-file-process . tramp-smb-handle-start-file-process)
(substitute-in-file-name . tramp-smb-handle-substitute-in-file-name)
- (unhandled-file-name-directory . tramp-handle-unhandled-file-name-directory)
+ (temporary-file-directory . tramp-handle-temporary-file-directory)
+ (unhandled-file-name-directory . ignore)
(vc-registered . ignore)
(verify-visited-file-modtime . tramp-handle-verify-visited-file-modtime)
(write-region . tramp-smb-handle-write-region))
@@ -291,7 +299,8 @@ If it isn't found in the local $PATH, the absolute path of winexe
shall be given. This is needed for remote processes."
:group 'tramp
:type 'string
- :version "24.3")
+ :version "24.3"
+ :require 'tramp)
;;;###tramp-autoload
(defcustom tramp-smb-winexe-shell-command "powershell.exe"
@@ -299,7 +308,8 @@ shall be given. This is needed for remote processes."
This must be Powershell V2 compatible."
:group 'tramp
:type 'string
- :version "24.3")
+ :version "24.3"
+ :require 'tramp)
;;;###tramp-autoload
(defcustom tramp-smb-winexe-shell-command-switch "-file -"
@@ -307,7 +317,8 @@ This must be Powershell V2 compatible."
This can be used to disable echo etc."
:group 'tramp
:type 'string
- :version "24.3")
+ :version "24.3"
+ :require 'tramp)
;; It must be a `defsubst' in order to push the whole code into
;; tramp-loaddefs.el. Otherwise, there would be recursive autoloading.
@@ -380,7 +391,7 @@ pass to the OPERATION."
(defun tramp-smb-action-with-tar (proc vec)
"Untar from connection buffer."
- (if (not (memq (process-status proc) '(run open)))
+ (if (not (tramp-compat-process-live-p proc))
(throw 'tramp-action 'process-died)
(with-current-buffer (tramp-get-connection-buffer vec)
@@ -419,15 +430,14 @@ pass to the OPERATION."
(unwind-protect
(progn
(make-directory tmpdir)
- (tramp-compat-copy-directory
- dirname tmpdir keep-date 'parents)
- (tramp-compat-copy-directory
+ (copy-directory dirname tmpdir keep-date 'parents)
+ (copy-directory
(expand-file-name (file-name-nondirectory dirname) tmpdir)
newname keep-date parents))
- (tramp-compat-delete-directory tmpdir 'recursive))))
+ (delete-directory tmpdir 'recursive))))
;; We can copy recursively.
- ((or t1 t2)
+ ((and (or t1 t2) (tramp-smb-get-cifs-capabilities v))
(when (and (file-directory-p newname)
(not (string-equal (file-name-nondirectory dirname)
(file-name-nondirectory newname))))
@@ -448,7 +458,7 @@ pass to the OPERATION."
(port (tramp-file-name-port v))
(share (tramp-smb-get-share v))
(localname (file-name-as-directory
- (tramp-compat-replace-regexp-in-string
+ (replace-regexp-in-string
"\\\\" "/" (tramp-smb-get-localname v))))
(tmpdir (make-temp-name
(expand-file-name
@@ -468,15 +478,19 @@ pass to the OPERATION."
(if t1
;; Source is remote.
(append args
- (list "-D" (shell-quote-argument localname)
+ (list "-D" (tramp-unquote-shell-quote-argument
+ localname)
"-c" (shell-quote-argument "tar qc - *")
"|" "tar" "xfC" "-"
- (shell-quote-argument tmpdir)))
+ (tramp-unquote-shell-quote-argument
+ tmpdir)))
;; Target is remote.
(append (list "tar" "cfC" "-"
- (shell-quote-argument dirname) "." "|")
+ (tramp-unquote-shell-quote-argument dirname)
+ "." "|")
args
- (list "-D" (shell-quote-argument localname)
+ (list "-D" (tramp-unquote-shell-quote-argument
+ localname)
"-c" (shell-quote-argument "tar qx -")))))
(unwind-protect
@@ -494,7 +508,8 @@ pass to the OPERATION."
;; target.
(make-directory
(expand-file-name
- ".." (concat tmpdir localname)) 'parents)
+ ".." (concat tmpdir localname))
+ 'parents)
(make-symbolic-link
newname (directory-file-name (concat tmpdir localname))))
@@ -510,21 +525,24 @@ pass to the OPERATION."
(tramp-message
v 6 "%s" (mapconcat 'identity (process-command p) " "))
(tramp-set-connection-property p "vector" v)
- (tramp-compat-set-process-query-on-exit-flag p nil)
+ (set-process-query-on-exit-flag p nil)
(tramp-process-actions p v nil tramp-smb-actions-with-tar)
- (while (memq (process-status p) '(run open))
+ (while (tramp-compat-process-live-p p)
(sit-for 0.1))
(tramp-message v 6 "\n%s" (buffer-string))))
;; Reset the transfer process properties.
(tramp-set-connection-property v "process-name" nil)
(tramp-set-connection-property v "process-buffer" nil)
- (when t1 (tramp-compat-delete-directory tmpdir 'recurse))))
+ (when t1 (delete-directory tmpdir 'recurse))))
;; Handle KEEP-DATE argument.
(when keep-date
- (set-file-times newname (nth 5 (file-attributes dirname))))
+ (set-file-times
+ newname
+ (tramp-compat-file-attribute-modification-time
+ (file-attributes dirname))))
;; Set the mode.
(unless keep-date
@@ -543,7 +561,7 @@ pass to the OPERATION."
(defun tramp-smb-handle-copy-file
(filename newname &optional ok-if-already-exists keep-date
- _preserve-uid-gid _preserve-extended-attributes)
+ _preserve-uid-gid _preserve-extended-attributes)
"Like `copy-file' for Tramp files.
KEEP-DATE has no effect in case NEWNAME resides on an SMB server.
PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
@@ -555,7 +573,8 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
0 (format "Copying %s to %s" filename newname)
(if (file-directory-p filename)
- (tramp-compat-copy-directory filename newname keep-date t t)
+ (tramp-compat-copy-directory
+ filename newname keep-date 'parents 'copy-contents)
(let ((tmpfile (file-local-copy filename)))
(if tmpfile
@@ -585,27 +604,30 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
v 'file-error "Target `%s' must contain a share name" newname))
(unless (tramp-smb-send-command
v (format "put \"%s\" \"%s\""
- filename (tramp-smb-get-localname v)))
+ (tramp-compat-file-name-unquote filename)
+ (tramp-smb-get-localname v)))
(tramp-error
v 'file-error "Cannot copy `%s' to `%s'" filename newname))))))
;; KEEP-DATE handling.
(when keep-date
- (set-file-times newname (nth 5 (file-attributes filename))))))
+ (set-file-times
+ newname
+ (tramp-compat-file-attribute-modification-time
+ (file-attributes filename))))))
(defun tramp-smb-handle-delete-directory (directory &optional recursive)
"Like `delete-directory' for Tramp files."
(setq directory (directory-file-name (expand-file-name directory)))
(when (file-exists-p directory)
- (if recursive
- (mapc
- (lambda (file)
- (if (file-directory-p file)
- (tramp-compat-delete-directory file recursive)
- (delete-file file)))
- ;; We do not want to delete "." and "..".
- (directory-files
- directory 'full "^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*")))
+ (when recursive
+ (mapc
+ (lambda (file)
+ (if (file-directory-p file)
+ (delete-directory file recursive)
+ (delete-file file)))
+ ;; We do not want to delete "." and "..".
+ (directory-files directory 'full directory-files-no-dot-files-regexp)))
(with-parsed-tramp-file-name directory nil
;; We must also flush the cache of the directory, because
@@ -664,8 +686,7 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
result)))
;; Sort them if necessary.
(unless nosort (setq result (sort result 'string-lessp)))
- ;; Remove double entries.
- (tramp-compat-delete-dups result)))
+ result))
(defun tramp-smb-handle-expand-file-name (name &optional dir)
"Like `expand-file-name' for Tramp files."
@@ -699,7 +720,7 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
(defun tramp-smb-action-get-acl (proc vec)
"Read ACL data from connection buffer."
- (when (not (memq (process-status proc) '(run open)))
+ (unless (tramp-compat-process-live-p proc)
;; Accept pending output.
(while (tramp-accept-process-output proc 0.1))
(with-current-buffer (tramp-get-connection-buffer vec)
@@ -730,7 +751,7 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
(domain (tramp-file-name-domain v))
(port (tramp-file-name-port v))
(share (tramp-smb-get-share v))
- (localname (tramp-compat-replace-regexp-in-string
+ (localname (replace-regexp-in-string
"\\\\" "/" (tramp-smb-get-localname v)))
(args (list (concat "//" real-host "/" share) "-E")))
@@ -744,7 +765,8 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
(setq args (append args (list "-s" tramp-smb-conf))))
(setq
args
- (append args (list (shell-quote-argument localname) "2>/dev/null")))
+ (append args (list (tramp-unquote-shell-quote-argument localname)
+ "2>/dev/null")))
(unwind-protect
(with-temp-buffer
@@ -765,11 +787,10 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
(tramp-message
v 6 "%s" (mapconcat 'identity (process-command p) " "))
(tramp-set-connection-property p "vector" v)
- (tramp-compat-set-process-query-on-exit-flag p nil)
+ (set-process-query-on-exit-flag p nil)
(tramp-process-actions p v nil tramp-smb-actions-get-acl)
(when (> (point-max) (point-min))
- (tramp-compat-funcall
- 'substring-no-properties (buffer-string)))))
+ (substring-no-properties (buffer-string)))))
;; Reset the transfer process properties.
(tramp-set-connection-property v "process-name" nil)
@@ -882,14 +903,16 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
(defun tramp-smb-handle-file-directory-p (filename)
"Like `file-directory-p' for Tramp files."
(and (file-exists-p filename)
- (eq ?d (aref (nth 8 (file-attributes filename)) 0))))
+ (eq ?d
+ (aref (tramp-compat-file-attribute-modes (file-attributes filename))
+ 0))))
(defun tramp-smb-handle-file-local-copy (filename)
"Like `file-local-copy' for Tramp files."
(with-parsed-tramp-file-name filename nil
(unless (file-exists-p filename)
(tramp-error
- v 'file-error
+ v tramp-file-missing
"Cannot make local copy of non-existing file `%s'" filename))
(let ((tmpfile (tramp-compat-make-temp-file filename)))
(with-tramp-progress-reporter
@@ -909,22 +932,24 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
"Like `file-name-all-completions' for Tramp files."
(all-completions
filename
- (with-parsed-tramp-file-name directory nil
+ (with-parsed-tramp-file-name (expand-file-name directory) nil
(with-tramp-file-property v localname "file-name-all-completions"
(save-match-data
- (let ((entries (tramp-smb-get-file-entries directory)))
- (mapcar
- (lambda (x)
- (list
- (if (string-match "d" (nth 1 x))
- (file-name-as-directory (nth 0 x))
- (nth 0 x))))
- entries)))))))
+ (delete-dups
+ (mapcar
+ (lambda (x)
+ (list
+ (if (string-match "d" (nth 1 x))
+ (file-name-as-directory (nth 0 x))
+ (nth 0 x))))
+ (tramp-smb-get-file-entries directory))))))))
(defun tramp-smb-handle-file-writable-p (filename)
"Like `file-writable-p' for Tramp files."
(if (file-exists-p filename)
- (string-match "w" (or (nth 8 (file-attributes filename)) ""))
+ (string-match
+ "w"
+ (or (tramp-compat-file-attribute-modes (file-attributes filename)) ""))
(let ((dir (file-name-directory filename)))
(and (file-exists-p dir)
(file-writable-p dir)))))
@@ -1009,11 +1034,11 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
(insert
(format
"%10s %3d %-8s %-8s %8s %s "
- (or (nth 8 attr) (nth 1 x)) ; mode
- (or (nth 1 attr) 1) ; inode
- (or (nth 2 attr) "nobody") ; uid
- (or (nth 3 attr) "nogroup") ; gid
- (or (nth 7 attr) (nth 2 x)) ; size
+ (or (tramp-compat-file-attribute-modes attr) (nth 1 x))
+ (or (tramp-compat-file-attribute-link-number attr) 1)
+ (or (tramp-compat-file-attribute-user-id attr) "nobody")
+ (or (tramp-compat-file-attribute-group-id attr) "nogroup")
+ (or (tramp-compat-file-attribute-size attr) (nth 2 x))
(format-time-string
(if (time-less-p (time-subtract (current-time) (nth 3 x))
tramp-half-a-year)
@@ -1068,9 +1093,7 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
(tramp-smb-send-command
v
(if (tramp-smb-get-cifs-capabilities v)
- (format
- "posix_mkdir \"%s\" %s"
- file (tramp-compat-decimal-to-octal (default-file-modes)))
+ (format "posix_mkdir \"%s\" %o" file (default-file-modes))
(format "mkdir \"%s\"" file)))
;; We must also flush the cache of the directory, because
;; `file-attributes' reads the values from there.
@@ -1112,7 +1135,7 @@ target of the symlink differ."
"File %s already exists; make it a new name anyway? "
linkname)))
(tramp-error
- v2 'file-error
+ v2 'file-already-exists
"make-symbolic-link: file %s already exists" linkname))
(unless (tramp-smb-get-cifs-capabilities v1)
(tramp-error v2 'file-error "make-symbolic-link not supported"))
@@ -1215,7 +1238,7 @@ target of the symlink differ."
(narrow-to-region (point-max) (point-max))
(let ((p (tramp-get-connection-process v)))
(tramp-smb-send-command v "exit $lasterrorcode")
- (while (memq (process-status p) '(run open))
+ (while (tramp-compat-process-live-p p)
(sleep-for 0.1)
(setq ret (process-exit-status p))))
(delete-region (point-min) (point-max))
@@ -1240,12 +1263,7 @@ target of the symlink differ."
(unless outbuf
(kill-buffer (tramp-get-connection-property v "process-buffer" nil)))
- ;; `process-file-side-effects' has been introduced with GNU
- ;; Emacs 23.2. If set to nil, no remote file will be changed
- ;; by `program'. If it doesn't exist, we assume its default
- ;; value t.
- (unless (and (boundp 'process-file-side-effects)
- (not (symbol-value 'process-file-side-effects)))
+ (unless process-file-side-effects
(tramp-flush-directory-property v ""))
;; Return exit status.
@@ -1296,14 +1314,15 @@ target of the symlink differ."
(tramp-error v2 'file-error "Cannot rename `%s'" filename))))
;; We must rename via copy.
- (tramp-compat-copy-file filename newname ok-if-already-exists t t t)
+ (copy-file
+ filename newname ok-if-already-exists 'keep-time 'preserve-uid-gid)
(if (file-directory-p filename)
- (tramp-compat-delete-directory filename 'recursive)
+ (delete-directory filename 'recursive)
(delete-file filename)))))
(defun tramp-smb-action-set-acl (proc vec)
"Read ACL data from connection buffer."
- (when (not (memq (process-status proc) '(run open)))
+ (unless (tramp-compat-process-live-p proc)
;; Accept pending output.
(while (tramp-accept-process-output proc 0.1))
(with-current-buffer (tramp-get-connection-buffer vec)
@@ -1325,10 +1344,10 @@ target of the symlink differ."
(domain (tramp-file-name-domain v))
(port (tramp-file-name-port v))
(share (tramp-smb-get-share v))
- (localname (tramp-compat-replace-regexp-in-string
+ (localname (replace-regexp-in-string
"\\\\" "/" (tramp-smb-get-localname v)))
(args (list (concat "//" real-host "/" share) "-E" "-S"
- (tramp-compat-replace-regexp-in-string
+ (replace-regexp-in-string
"\n" "," acl-string))))
(if (not (zerop (length real-user)))
@@ -1341,7 +1360,7 @@ target of the symlink differ."
(setq args (append args (list "-s" tramp-smb-conf))))
(setq
args
- (append args (list (shell-quote-argument localname)
+ (append args (list (tramp-unquote-shell-quote-argument localname)
"&&" "echo" "tramp_exit_status" "0"
"||" "echo" "tramp_exit_status" "1")))
@@ -1364,7 +1383,7 @@ target of the symlink differ."
(tramp-message
v 6 "%s" (mapconcat 'identity (process-command p) " "))
(tramp-set-connection-property p "vector" v)
- (tramp-compat-set-process-query-on-exit-flag p nil)
+ (set-process-query-on-exit-flag p nil)
(tramp-process-actions p v nil tramp-smb-actions-set-acl)
(goto-char (point-max))
(unless (re-search-backward "tramp_exit_status [0-9]+" nil t)
@@ -1387,9 +1406,7 @@ target of the symlink differ."
(when (tramp-smb-get-cifs-capabilities v)
(tramp-flush-file-property v localname)
(unless (tramp-smb-send-command
- v (format "chmod \"%s\" %s"
- (tramp-smb-get-localname v)
- (tramp-compat-decimal-to-octal mode)))
+ v (format "chmod \"%s\" %o" (tramp-smb-get-localname v) mode))
(tramp-error
v 'file-error "Error while changing file's mode %s" filename)))))
@@ -1399,16 +1416,18 @@ target of the symlink differ."
(defun tramp-smb-handle-start-file-process (name buffer program &rest args)
"Like `start-file-process' for Tramp files."
(with-parsed-tramp-file-name default-directory nil
- (let ((command (mapconcat 'identity (cons program args) " "))
- (bmp (and (buffer-live-p buffer) (buffer-modified-p buffer)))
- (name1 name)
- (i 0))
+ (let* ((buffer
+ (if buffer
+ (get-buffer-create buffer)
+ ;; BUFFER can be nil. We use a temporary buffer.
+ (generate-new-buffer tramp-temp-buffer-name)))
+ (command (mapconcat 'identity (cons program args) " "))
+ (bmp (and (buffer-live-p buffer) (buffer-modified-p buffer)))
+ (name1 name)
+ (i 0))
(unwind-protect
(save-excursion
(save-restriction
- (unless buffer
- ;; BUFFER can be nil. We use a temporary buffer.
- (setq buffer (generate-new-buffer tramp-temp-buffer-name)))
(while (get-process name1)
;; NAME must be unique as process name.
(setq i (1+ i)
@@ -1445,24 +1464,25 @@ target of the symlink differ."
"Like `handle-substitute-in-file-name' for Tramp files.
\"//\" substitutes only in the local filename part. Catches
errors for shares like \"C$/\", which are common in Microsoft Windows."
- (with-parsed-tramp-file-name filename nil
- ;; Ignore in LOCALNAME everything before "//".
- (when (and (stringp localname) (string-match ".+?/\\(/\\|~\\)" localname))
- (setq filename
- (concat (file-remote-p filename)
- (replace-match "\\1" nil nil localname)))))
- (condition-case nil
- (tramp-run-real-handler 'substitute-in-file-name (list filename))
- (error filename)))
+ ;; Check, whether the local part is a quoted file name.
+ (if (tramp-compat-file-name-quoted-p filename)
+ filename
+ (with-parsed-tramp-file-name filename nil
+ ;; Ignore in LOCALNAME everything before "//".
+ (when (and (stringp localname) (string-match ".+?/\\(/\\|~\\)" localname))
+ (setq filename
+ (concat (file-remote-p filename)
+ (replace-match "\\1" nil nil localname)))))
+ (condition-case nil
+ (tramp-run-real-handler 'substitute-in-file-name (list filename))
+ (error filename))))
(defun tramp-smb-handle-write-region
(start end filename &optional append visit lockname confirm)
"Like `write-region' for Tramp files."
(setq filename (expand-file-name filename))
(with-parsed-tramp-file-name filename nil
- ;; XEmacs takes a coding system as the seventh argument, not `confirm'.
- (when (and (not (featurep 'xemacs))
- confirm (file-exists-p filename))
+ (when (and confirm (file-exists-p filename))
(unless (y-or-n-p (format "File %s exists; overwrite anyway? "
filename))
(tramp-error v 'file-error "File not overwritten")))
@@ -1505,7 +1525,7 @@ errors for shares like \"C$/\", which are common in Microsoft Windows."
(defun tramp-smb-get-share (vec)
"Returns the share name of LOCALNAME."
(save-match-data
- (let ((localname (tramp-file-name-localname vec)))
+ (let ((localname (tramp-file-name-unquote-localname vec)))
(when (string-match "^/?\\([^/]+\\)/" localname)
(match-string 1 localname)))))
@@ -1513,7 +1533,7 @@ errors for shares like \"C$/\", which are common in Microsoft Windows."
"Returns the file name of LOCALNAME.
If VEC has no cifs capabilities, exchange \"/\" by \"\\\\\"."
(save-match-data
- (let ((localname (tramp-file-name-localname vec)))
+ (let ((localname (tramp-file-name-unquote-localname vec)))
(setq
localname
(if (string-match "^/?[^/]+\\(/.*\\)" localname)
@@ -1575,10 +1595,6 @@ Result is a list of (LOCALNAME MODE SIZE MONTH DAY TIME YEAR)."
;; Add directory itself.
(push '("" "drwxrwxrwx" 0 (0 0)) res)
- ;; There's a very strange error (debugged with XEmacs 21.4.14)
- ;; If there's no short delay, it returns nil. No idea about.
- (when (featurep 'xemacs) (sleep-for 0.01))
-
;; Return entries.
(delq nil res))))))
@@ -1717,7 +1733,7 @@ Result is the list (LOCALNAME MODE SIZE MTIME)."
(if (and sec min hour day month year)
(encode-time
sec min hour day
- (cdr (assoc (downcase month) tramp-parse-time-months))
+ (cdr (assoc (downcase month) parse-time-months))
year)
'(0 0)))
(list localname mode size mtime))))
@@ -1725,8 +1741,7 @@ Result is the list (LOCALNAME MODE SIZE MTIME)."
(defun tramp-smb-get-cifs-capabilities (vec)
"Check, whether the SMB server supports POSIX commands."
;; When we are not logged in yet, we return nil.
- (if (let ((p (tramp-get-connection-process vec)))
- (and p (processp p) (memq (process-status p) '(run open))))
+ (if (tramp-compat-process-live-p (tramp-get-connection-process vec))
(with-tramp-connection-property
(tramp-get-connection-process vec) "cifs-capabilities"
(save-match-data
@@ -1738,14 +1753,13 @@ Result is the list (LOCALNAME MODE SIZE MTIME)."
(member
"pathnames"
(split-string
- (buffer-substring (point) (point-at-eol)) nil t)))))))))
+ (buffer-substring (point) (point-at-eol)) nil 'omit)))))))))
(defun tramp-smb-get-stat-capability (vec)
"Check, whether the SMB server supports the STAT command."
;; When we are not logged in yet, we return nil.
(if (and (tramp-smb-get-share vec)
- (let ((p (tramp-get-connection-process vec)))
- (and p (processp p) (memq (process-status p) '(run open)))))
+ (tramp-compat-process-live-p (tramp-get-connection-process vec)))
(with-tramp-connection-property
(tramp-get-connection-process vec) "stat-capability"
(tramp-smb-send-command vec "stat \"/\""))))
@@ -1812,18 +1826,17 @@ If ARGUMENT is non-nil, use it as argument for
(tramp-get-connection-property
p "last-cmd-time" '(0 0 0)))
60)
- p (processp p) (memq (process-status p) '(run open))
+ (tramp-compat-process-live-p p)
(re-search-forward tramp-smb-errors nil t))
(delete-process p)
(setq p nil)))
;; Check whether it is still the same share.
- (unless
- (and p (processp p) (memq (process-status p) '(run open))
- (or argument
- (string-equal
- share
- (tramp-get-connection-property p "smb-share" ""))))
+ (unless (and (tramp-compat-process-live-p p)
+ (or argument
+ (string-equal
+ share
+ (tramp-get-connection-property p "smb-share" ""))))
(save-match-data
;; There might be unread output from checking for share names.
@@ -1878,7 +1891,7 @@ If ARGUMENT is non-nil, use it as argument for
(tramp-message
vec 6 "%s" (mapconcat 'identity (process-command p) " "))
(tramp-set-connection-property p "vector" vec)
- (tramp-compat-set-process-query-on-exit-flag p nil)
+ (set-process-query-on-exit-flag p nil)
;; Set variables for computing the prompt for reading password.
(setq tramp-current-method tramp-smb-method
@@ -1916,6 +1929,9 @@ If ARGUMENT is non-nil, use it as argument for
(tramp-set-connection-property p "smb-share" share)
(tramp-set-connection-property p "chunksize" 1)
+ ;; Set connection-local variables.
+ (tramp-set-connection-local-variables vec)
+
;; Mark it as connected.
(tramp-set-connection-property p "connected" t))
@@ -1954,7 +1970,7 @@ Returns nil if an error message has appeared."
;; Algorithm: get waiting output. See if last line contains
;; `tramp-smb-prompt' sentinel or `tramp-smb-errors' strings.
;; If not, wait a bit and again get waiting output.
- (while (and (not found) (not err) (memq (process-status p) '(run open)))
+ (while (and (not found) (not err) (tramp-compat-process-live-p p))
;; Accept pending output.
(tramp-accept-process-output p 0.1)
@@ -1968,7 +1984,7 @@ Returns nil if an error message has appeared."
(setq err (re-search-forward tramp-smb-errors nil t)))
;; When the process is still alive, read pending output.
- (while (and (not found) (memq (process-status p) '(run open)))
+ (while (and (not found) (tramp-compat-process-live-p p))
;; Accept pending output.
(tramp-accept-process-output p 0.1)
@@ -1992,7 +2008,7 @@ Returns nil if an error message has appeared."
"Send SIGKILL to the winexe process."
(ignore-errors
(let ((p (get-buffer-process (current-buffer))))
- (when (and p (processp p) (memq (process-status p) '(run open)))
+ (when (tramp-compat-process-live-p p)
(signal-process (process-id p) 'SIGINT)))))
(defun tramp-smb-call-winexe (vec)
@@ -2031,7 +2047,7 @@ Returns nil if an error message has appeared."
(defun tramp-smb-shell-quote-argument (s)
"Similar to `shell-quote-argument', but uses windows cmd syntax."
(let ((system-type 'ms-dos))
- (shell-quote-argument s)))
+ (tramp-unquote-shell-quote-argument s)))
(add-hook 'tramp-unload-hook
(lambda ()
@@ -2042,8 +2058,10 @@ Returns nil if an error message has appeared."
;;; TODO:
;; * Return more comprehensive file permission string.
+;;
;; * Try to remove the inclusion of dummy "" directory. Seems to be at
;; several places, especially in `tramp-smb-handle-insert-directory'.
+;;
;; * Ignore case in file names.
;;; tramp-smb.el ends here
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index 5d8081cd815..7b5f71a754f 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -34,9 +34,7 @@
;; Notes:
;; -----
;;
-;; This package only works for Emacs 22.1 and higher, and for XEmacs 21.4
-;; and higher. For XEmacs 21, you need the package `fsf-compat' for
-;; the `with-timeout' macro.
+;; This package only works for Emacs 23.1 and higher.
;;
;; Also see the todo list at the bottom of this file.
;;
@@ -61,11 +59,7 @@
;; Pacify byte-compiler.
(eval-when-compile
(require 'cl))
-(defvar bkup-backup-directory-info)
-(defvar directory-sep-char)
(defvar eshell-path-env)
-(defvar ls-lisp-use-insert-directory-program)
-(defvar outline-regexp)
;;; User Customizable Internal Variables:
@@ -82,7 +76,8 @@
"Whether Tramp is enabled.
If it is set to nil, all remote file names are used literally."
:group 'tramp
- :type 'boolean)
+ :type 'boolean
+ :require 'tramp)
(defcustom tramp-verbose 3
"Verbosity level for Tramp messages.
@@ -100,13 +95,11 @@ Any level x includes messages for all levels 1 .. x-1. The levels are
9 test commands
10 traces (huge)."
:group 'tramp
- :type 'integer)
+ :type 'integer
+ :require 'tramp)
-;; Emacs case.
-(eval-and-compile
- (when (boundp 'backup-directory-alist)
- (defcustom tramp-backup-directory-alist nil
- "Alist of filename patterns and backup directory names.
+(defcustom tramp-backup-directory-alist nil
+ "Alist of filename patterns and backup directory names.
Each element looks like (REGEXP . DIRECTORY), with the same meaning like
in `backup-directory-alist'. If a Tramp file is backed up, and DIRECTORY
is a local file name, the backup directory is prepended with Tramp file
@@ -116,34 +109,10 @@ name prefix \(method, user, host) of file.
gives the same backup policy for Tramp files on their hosts like the
policy for local files."
- :group 'tramp
- :type '(repeat (cons (regexp :tag "Regexp matching filename")
- (directory :tag "Backup directory name"))))))
-
-;; XEmacs case. We cannot check for `bkup-backup-directory-info', because
-;; the package "backup-dir" might not be loaded yet.
-(eval-and-compile
- (when (featurep 'xemacs)
- (defcustom tramp-bkup-backup-directory-info nil
- "Alist of (FILE-REGEXP BACKUP-DIR OPTIONS ...))
-It has the same meaning like `bkup-backup-directory-info' from package
-`backup-dir'. If a Tramp file is backed up, and BACKUP-DIR is a local
-file name, the backup directory is prepended with Tramp file name prefix
-\(method, user, host) of file.
-
-\(setq tramp-bkup-backup-directory-info bkup-backup-directory-info)
-
-gives the same backup policy for Tramp files on their hosts like the
-policy for local files."
- :type '(repeat
- (list (regexp :tag "File regexp")
- (string :tag "Backup Dir")
- (set :inline t
- (const ok-create)
- (const full-path)
- (const prepend-name)
- (const search-upward))))
- :group 'tramp)))
+ :group 'tramp
+ :type '(repeat (cons (regexp :tag "Regexp matching filename")
+ (directory :tag "Backup directory name")))
+ :require 'tramp)
(defcustom tramp-auto-save-directory nil
"Put auto-save files in this directory, if set.
@@ -151,12 +120,11 @@ The idea is to use a local directory so that auto-saving is faster.
This setting has precedence over `auto-save-file-name-transforms'."
:group 'tramp
:type '(choice (const :tag "Use default" nil)
- (directory :tag "Auto save directory name")))
+ (directory :tag "Auto save directory name"))
+ :require 'tramp)
(defcustom tramp-encoding-shell
- (if (memq system-type '(windows-nt))
- (getenv "COMSPEC")
- "/bin/sh")
+ (or (tramp-compat-funcall 'w32-shell-name) "/bin/sh")
"Use this program for encoding and decoding commands on the local host.
This shell is used to execute the encoding and decoding command on the
local host, so if you want to use `~' in those commands, you should
@@ -177,24 +145,25 @@ Note that this variable is not used for remote commands. There are
mechanisms in tramp.el which automatically determine the right shell to
use for the remote host."
:group 'tramp
- :type '(file :must-match t))
+ :type '(file :must-match t)
+ :require 'tramp)
(defcustom tramp-encoding-command-switch
- (if (string-match "cmd\\.exe" (or tramp-encoding-shell ""))
- "/c"
- "-c")
+ (if (tramp-compat-funcall 'w32-shell-dos-semantics) "/c" "-c")
"Use this switch together with `tramp-encoding-shell' for local commands.
See the variable `tramp-encoding-shell' for more information."
:group 'tramp
- :type 'string)
+ :type 'string
+ :require 'tramp)
(defcustom tramp-encoding-command-interactive
- (unless (string-match "cmd\\.exe" (or tramp-encoding-shell "")) "-i")
+ (unless (tramp-compat-funcall 'w32-shell-dos-semantics) "-i")
"Use this switch together with `tramp-encoding-shell' for interactive shells.
See the variable `tramp-encoding-shell' for more information."
:version "24.1"
:group 'tramp
- :type '(choice (const nil) string))
+ :type '(choice (const nil) string)
+ :require 'tramp)
;;;###tramp-autoload
(defvar tramp-methods nil
@@ -272,12 +241,7 @@ pair of the form (KEY VALUE). The following KEYs are defined:
* `tramp-copy-recursive'
Whether the operation copies directories recursively.
* `tramp-default-port'
- The default port of a method is needed in case of gateway connections.
- Additionally, it is used as indication which method is prepared for
- passing gateways.
- * `tramp-gw-args'
- As the attribute name says, additional arguments are specified here
- when a method is applied via a gateway.
+ The default port of a method.
* `tramp-tmpdir'
A directory on the remote host for temporary files. If not
specified, \"/tmp\" is taken as default.
@@ -286,6 +250,11 @@ pair of the form (KEY VALUE). The following KEYs are defined:
In general, the global default value shall be used, but for
some methods, like \"su\" or \"sudo\", a shorter timeout
might be desirable.
+ * `tramp-case-insensitive'
+ Whether the remote file system handles file names case insensitive.
+ Only a non-nil value counts, the default value nil means to
+ perform further checks on the remote host. See
+ `tramp-connection-properties' for a way to overwrite this.
What does all this mean? Well, you should specify `tramp-login-program'
for all methods; this program is used to log in to the remote site. Then,
@@ -303,8 +272,7 @@ See the variables `tramp-local-coding-commands' and
So, to summarize: if the method is an out-of-band method, then you
must specify `tramp-copy-program' and `tramp-copy-args'. If it is an
-inline method, then these two parameters should be nil. Methods which
-are fit for gateways must have `tramp-default-port' at least.
+inline method, then these two parameters should be nil.
Notes:
@@ -329,32 +297,17 @@ useful only in combination with `tramp-default-proxies-alist'.")
;; PuTTY is installed. We don't take it, if it is installed on a
;; non-windows system, or pscp from the pssh (parallel ssh) package
;; is found.
- ((and (eq system-type 'windows-nt)
- (executable-find "pscp"))
- (if (or (fboundp 'password-read)
- (fboundp 'auth-source-user-or-password)
- (fboundp 'auth-source-search)
- ;; Pageant is running.
- (tramp-compat-process-running-p "Pageant"))
- "pscp"
- "plink"))
+ ((and (eq system-type 'windows-nt) (executable-find "pscp")) "pscp")
;; There is an ssh installation.
- ((executable-find "scp")
- (if (or (fboundp 'password-read)
- (fboundp 'auth-source-user-or-password)
- (fboundp 'auth-source-search)
- ;; ssh-agent is running.
- (getenv "SSH_AUTH_SOCK")
- (getenv "SSH_AGENT_PID"))
- "scp"
- "ssh"))
+ ((executable-find "scp") "scp")
;; Fallback.
(t "ftp"))
"Default method to use for transferring files.
See `tramp-methods' for possibilities.
Also see `tramp-default-method-alist'."
:group 'tramp
- :type 'string)
+ :type 'string
+ :require 'tramp)
;;;###tramp-autoload
(defcustom tramp-default-method-alist nil
@@ -372,7 +325,8 @@ See `tramp-methods' for a list of possibilities for METHOD."
:group 'tramp
:type '(repeat (list (choice :tag "Host regexp" regexp sexp)
(choice :tag "User regexp" regexp sexp)
- (choice :tag "Method name" string (const nil)))))
+ (choice :tag "Method name" string (const nil))))
+ :require 'tramp)
(defcustom tramp-default-user nil
"Default user to use for transferring files.
@@ -381,7 +335,8 @@ It is nil by default; otherwise settings in configuration files like
This variable is regarded as obsolete, and will be removed soon."
:group 'tramp
- :type '(choice (const nil) string))
+ :type '(choice (const nil) string)
+ :require 'tramp)
;;;###tramp-autoload
(defcustom tramp-default-user-alist nil
@@ -397,13 +352,15 @@ empty string for the method name."
:group 'tramp
:type '(repeat (list (choice :tag "Method regexp" regexp sexp)
(choice :tag " Host regexp" regexp sexp)
- (choice :tag " User name" string (const nil)))))
+ (choice :tag " User name" string (const nil))))
+ :require 'tramp)
(defcustom tramp-default-host (system-name)
"Default host to use for transferring files.
Useful for su and sudo methods mostly."
:group 'tramp
- :type 'string)
+ :type 'string
+ :require 'tramp)
;;;###tramp-autoload
(defcustom tramp-default-host-alist nil
@@ -420,7 +377,8 @@ empty string for the method name."
:version "24.4"
:type '(repeat (list (choice :tag "Method regexp" regexp sexp)
(choice :tag " User regexp" regexp sexp)
- (choice :tag " Host name" string (const nil)))))
+ (choice :tag " Host name" string (const nil))))
+ :require 'tramp)
(defcustom tramp-default-proxies-alist nil
"Route to be followed for specific host/user pairs.
@@ -439,13 +397,15 @@ interpreted as a regular expression which always matches."
:group 'tramp
:type '(repeat (list (choice :tag "Host regexp" regexp sexp)
(choice :tag "User regexp" regexp sexp)
- (choice :tag " Proxy name" string (const nil)))))
+ (choice :tag " Proxy name" string (const nil))))
+ :require 'tramp)
(defcustom tramp-save-ad-hoc-proxies nil
"Whether to save ad-hoc proxies persistently."
:group 'tramp
:version "24.3"
- :type 'boolean)
+ :type 'boolean
+ :require 'tramp)
(defcustom tramp-restricted-shell-hosts-alist
(when (memq system-type '(windows-nt))
@@ -457,7 +417,8 @@ proxies only, see `tramp-default-proxies-alist'. If the local
host runs a registered shell, it shall be added to this list, too."
:version "24.3"
:group 'tramp
- :type '(repeat (regexp :tag "Host regexp")))
+ :type '(repeat (regexp :tag "Host regexp"))
+ :require 'tramp)
;;;###tramp-autoload
(defconst tramp-local-host-regexp
@@ -482,6 +443,7 @@ names from FILE for completion. The following predefined FUNCTIONs exists:
* `tramp-parse-sknownhosts' for \"~/.ssh2/knownhosts/*\" like files,
* `tramp-parse-hosts' for \"/etc/hosts\" like files,
* `tramp-parse-passwd' for \"/etc/passwd\" like files.
+ * `tramp-parse-etc-group' for \"/etc/group\" like files.
* `tramp-parse-netrc' for \"~/.netrc\" like files.
* `tramp-parse-putty' for PuTTY registered sessions.
@@ -517,14 +479,16 @@ the remote shell.")
"String used for end of line in local processes."
:version "24.1"
:group 'tramp
- :type 'string)
+ :type 'string
+ :require 'tramp)
(defcustom tramp-rsh-end-of-line "\n"
"String used for end of line in rsh connections.
I don't think this ever needs to be changed, so please tell me about it
if you need to change this."
:group 'tramp
- :type 'string)
+ :type 'string
+ :require 'tramp)
(defcustom tramp-login-prompt-regexp
".*\\(user\\|login\\)\\( .*\\)?: *"
@@ -533,7 +497,8 @@ The regexp should match at end of buffer.
Sometimes the prompt is reported to look like \"login as:\"."
:group 'tramp
- :type 'regexp)
+ :type 'regexp
+ :require 'tramp)
(defcustom tramp-shell-prompt-pattern
;; Allow a prompt to start right after a ^M since it indeed would be
@@ -541,7 +506,7 @@ Sometimes the prompt is reported to look like \"login as:\"."
;; regexp works only for GNU Emacs.
;; Allow also [] style prompts. They can appear only during
;; connection initialization; Tramp redefines the prompt afterwards.
- (concat (if (featurep 'xemacs) "" "\\(?:^\\|\r\\)")
+ (concat "\\(?:^\\|\r\\)"
"[^]#$%>\n]*#?[]#$%>] *\\(\e\\[[0-9;]*[a-zA-Z] *\\)*")
"Regexp to match prompts from remote shell.
Normally, Tramp expects you to configure `shell-prompt-pattern'
@@ -555,10 +520,12 @@ which should work well in many cases.
This regexp must match both `tramp-initial-end-of-output' and
`tramp-end-of-output'."
:group 'tramp
- :type 'regexp)
+ :type 'regexp
+ :require 'tramp)
(defcustom tramp-password-prompt-regexp
(format "^.*\\(%s\\).*:\^@? *"
+ ;; `password-word-equivalents' has been introduced with Emacs 24.4.
(if (boundp 'password-word-equivalents)
(regexp-opt (symbol-value 'password-word-equivalents))
"password\\|passphrase"))
@@ -568,7 +535,8 @@ The regexp should match at end of buffer.
The `sudo' program appears to insert a `^@' character into the prompt."
:version "24.4"
:group 'tramp
- :type 'regexp)
+ :type 'regexp
+ :require 'tramp)
(defcustom tramp-wrong-passwd-regexp
(concat "^.*"
@@ -592,7 +560,8 @@ The `sudo' program appears to insert a `^@' character into the prompt."
"Regexp matching a `login failed' message.
The regexp should match at end of buffer."
:group 'tramp
- :type 'regexp)
+ :type 'regexp
+ :require 'tramp)
(defcustom tramp-yesno-prompt-regexp
(concat
@@ -603,19 +572,22 @@ The confirmation should be done with yes or no.
The regexp should match at end of buffer.
See also `tramp-yn-prompt-regexp'."
:group 'tramp
- :type 'regexp)
+ :type 'regexp
+ :require 'tramp)
(defcustom tramp-yn-prompt-regexp
(concat
(regexp-opt '("Store key in cache? (y/n)"
- "Update cached key? (y/n, Return cancels connection)") t)
+ "Update cached key? (y/n, Return cancels connection)")
+ t)
"\\s-*")
"Regular expression matching all y/n queries which need to be confirmed.
The confirmation should be done with y or n.
The regexp should match at end of buffer.
See also `tramp-yesno-prompt-regexp'."
:group 'tramp
- :type 'regexp)
+ :type 'regexp
+ :require 'tramp)
(defcustom tramp-terminal-prompt-regexp
(concat "\\("
@@ -627,7 +599,8 @@ See also `tramp-yesno-prompt-regexp'."
The regexp should match at end of buffer.
The answer will be provided by `tramp-action-terminal', which see."
:group 'tramp
- :type 'regexp)
+ :type 'regexp
+ :require 'tramp)
(defcustom tramp-operation-not-permitted-regexp
(concat "\\(" "preserving times.*" "\\|" "set mode" "\\)" ":\\s-*"
@@ -636,18 +609,21 @@ The answer will be provided by `tramp-action-terminal', which see."
Copying has been performed successfully already, so this message can
be ignored safely."
:group 'tramp
- :type 'regexp)
+ :type 'regexp
+ :require 'tramp)
(defcustom tramp-copy-failed-regexp
(concat "\\(.+: "
(regexp-opt '("Permission denied"
"not a regular file"
"is a directory"
- "No such file or directory") t)
+ "No such file or directory")
+ t)
"\\)\\s-*")
"Regular expression matching copy problems in (s)cp operations."
:group 'tramp
- :type 'regexp)
+ :type 'regexp
+ :require 'tramp)
(defcustom tramp-process-alive-regexp
""
@@ -657,7 +633,8 @@ check regularly the status of the associated process.
The answer will be provided by `tramp-action-process-alive',
`tramp-action-out-of-band', which see."
:group 'tramp
- :type 'regexp)
+ :type 'regexp
+ :require 'tramp)
(defconst tramp-temp-name-prefix "tramp."
"Prefix to use for temporary files.
@@ -677,29 +654,19 @@ Useful for \"rsync\" like methods.")
(make-variable-buffer-local 'tramp-temp-buffer-file-name)
(put 'tramp-temp-buffer-file-name 'permanent-local t)
-;; XEmacs is distributed with few Lisp packages. Further packages are
-;; installed using EFS. If we use a unified filename format, then
-;; Tramp is required in addition to EFS. (But why can't Tramp just
-;; disable EFS when Tramp is loaded? Then XEmacs can ship with EFS
-;; just like before.) Another reason for using a separate filename
-;; syntax on XEmacs is that EFS hooks into XEmacs in many places, but
-;; Tramp only knows how to deal with `file-name-handler-alist', not
-;; the other places.
-
-;; Currently, we have the choice between 'ftp and 'sep.
;;;###autoload
-(defcustom tramp-syntax
- (if (featurep 'xemacs) 'sep 'ftp)
+(defcustom tramp-syntax 'ftp
"Tramp filename syntax to be used.
It can have the following values:
- `ftp' -- Ange-FTP respective EFS like syntax (GNU Emacs default)
- `sep' -- Syntax as defined for XEmacs."
+ `ftp' -- Ange-FTP like syntax
+ `sep' -- Syntax as defined for XEmacs originally."
:group 'tramp
:version "24.4"
- :type `(choice (const :tag ,(if (featurep 'xemacs) "EFS" "Ange-FTP") ftp)
- (const :tag "XEmacs" sep)))
+ :type '(choice (const :tag "Ange-FTP" ftp)
+ (const :tag "XEmacs" sep))
+ :require 'tramp)
(defconst tramp-prefix-format
(cond ((equal tramp-syntax 'ftp) "/")
@@ -837,6 +804,12 @@ Derived from `tramp-postfix-host-format'.")
(defconst tramp-localname-regexp ".*$"
"Regexp matching localnames.")
+(defconst tramp-unknown-id-string "UNKNOWN"
+ "String used to denote an unknown user or group")
+
+(defconst tramp-unknown-id-integer -1
+ "Integer used to denote an unknown user or group")
+
;;; File name format:
(defconst tramp-remote-file-name-spec-regexp
@@ -847,7 +820,7 @@ Derived from `tramp-postfix-host-format'.")
tramp-prefix-ipv6-regexp "\\(?:" tramp-ipv6-regexp "\\)?"
tramp-postfix-ipv6-regexp "\\)"
"\\(?:" tramp-prefix-port-regexp tramp-port-regexp "\\)?" "\\)?")
-"Regular expression matching a Tramp file name between prefix and postfix.")
+ "Regular expression matching a Tramp file name between prefix and postfix.")
(defconst tramp-file-name-structure
(list
@@ -883,43 +856,30 @@ See also `tramp-file-name-regexp'.")
"\\`/\\(\\[.*\\]\\|[^/|:]\\{2,\\}[^/|]*\\):"
"\\`/[^/|:][^/|]*:")
"Value for `tramp-file-name-regexp' for unified remoting.
-Emacs (not XEmacs) uses a unified filename syntax for Ange-FTP and
-Tramp. See `tramp-file-name-structure' for more explanations.
+See `tramp-file-name-structure' for more explanations.
On W32 systems, the volume letter must be ignored.")
;;;###autoload
(defconst tramp-file-name-regexp-separate "\\`/\\[.*\\]"
"Value for `tramp-file-name-regexp' for separate remoting.
-XEmacs uses a separate filename syntax for Tramp and EFS.
See `tramp-file-name-structure' for more explanations.")
;;;###autoload
-(defconst tramp-file-name-regexp
+(defvar tramp-file-name-regexp
(cond ((equal tramp-syntax 'ftp) tramp-file-name-regexp-unified)
((equal tramp-syntax 'sep) tramp-file-name-regexp-separate)
(t (error "Wrong `tramp-syntax' defined")))
"Regular expression matching file names handled by Tramp.
-This regexp should match Tramp file names but no other file names.
-When tramp.el is loaded, this regular expression is prepended to
-`file-name-handler-alist', and that is searched sequentially. Thus,
-if the Tramp entry appears rather early in the `file-name-handler-alist'
-and is a bit too general, then some files might be considered Tramp
-files which are not really Tramp files.
-
-Please note that the entry in `file-name-handler-alist' is made when
-this file \(tramp.el) is loaded. This means that this variable must be set
-before loading tramp.el. Alternatively, `file-name-handler-alist' can be
-updated after changing this variable.
-
-Also see `tramp-file-name-structure'.")
+This regexp should match Tramp file names but no other file
+names. When calling `tramp-register-file-name-handlers', the
+initial value is overwritten by the car of `tramp-file-name-structure'.")
;;;###autoload
(defconst tramp-completion-file-name-regexp-unified
(if (memq system-type '(cygwin windows-nt))
"\\`/[^/]\\{2,\\}\\'" "\\`/[^/]*\\'")
"Value for `tramp-completion-file-name-regexp' for unified remoting.
-GNU Emacs uses a unified filename syntax for Tramp and Ange-FTP.
See `tramp-file-name-structure' for more explanations.
On W32 systems, the volume letter must be ignored.")
@@ -928,7 +888,6 @@ On W32 systems, the volume letter must be ignored.")
(defconst tramp-completion-file-name-regexp-separate
"\\`/\\([[][^]]*\\)?\\'"
"Value for `tramp-completion-file-name-regexp' for separate remoting.
-XEmacs uses a separate filename syntax for Tramp and EFS.
See `tramp-file-name-structure' for more explanations.")
;;;###autoload
@@ -951,10 +910,7 @@ Also see `tramp-file-name-structure'.")
;; to drop bytes when data is sent too quickly. There is also a connection
;; buffer local variable, which is computed depending on remote host properties
;; when `tramp-chunksize' is zero or nil.
-(defcustom tramp-chunksize
- (when (and (not (featurep 'xemacs))
- (memq system-type '(hpux)))
- 500)
+(defcustom tramp-chunksize (when (memq system-type '(hpux)) 500)
;; Parentheses in docstring starting at beginning of line are escaped.
;; Fontification is messed up when
;; `open-paren-in-column-0-is-defun-start' set to t.
@@ -972,14 +928,14 @@ checked via the following code:
(erase-buffer)
(let ((proc (start-process (buffer-name) (current-buffer)
\"ssh\" \"-l\" user host \"wc\" \"-c\")))
- (when (memq (process-status proc) \\='(run open))
+ (when (process-live-p proc)
(process-send-string proc (make-string sent ?\\ ))
(process-send-eof proc)
(process-send-eof proc))
(while (not (progn (goto-char (point-min))
(re-search-forward \"\\\\w+\" (point-max) t)))
(accept-process-output proc 1))
- (when (memq (process-status proc) \\='(run open))
+ (when (process-live-p proc)
(setq received (string-to-number (match-string 0)))
(delete-process proc)
(message \"Bytes sent: %s\\tBytes received: %s\" sent received)
@@ -1015,7 +971,8 @@ in the third line of the code.
Please raise a bug report via \"M-x tramp-bug\" if your system needs
this variable to be set as well."
:group 'tramp
- :type '(choice (const nil) integer))
+ :type '(choice (const nil) integer)
+ :require 'tramp)
;; Logging in to a remote host normally requires obtaining a pty. But
;; Emacs on macOS has process-connection-type set to nil by default,
@@ -1026,7 +983,8 @@ this variable to be set as well."
Tramp binds `process-connection-type' to the value given here before
opening a connection to a remote host."
:group 'tramp
- :type '(choice (const nil) (const t) (const pty)))
+ :type '(choice (const nil) (const t) (const pty))
+ :require 'tramp)
(defcustom tramp-connection-timeout 60
"Defines the max time to wait for establishing a connection (in seconds).
@@ -1035,7 +993,8 @@ This can be overwritten for different connection types in `tramp-methods'.
The timeout does not include the time reading a password."
:group 'tramp
:version "24.4"
- :type 'integer)
+ :type 'integer
+ :require 'tramp)
(defcustom tramp-connection-min-time-diff 5
"Defines seconds between two consecutive connection attempts.
@@ -1049,7 +1008,8 @@ in a short time frame. In those cases it is recommended to
let-bind this variable."
:group 'tramp
:version "24.4"
- :type '(choice (const nil) integer))
+ :type '(choice (const nil) integer)
+ :require 'tramp)
(defcustom tramp-completion-reread-directory-timeout 10
"Defines seconds since last remote command before rereading a directory.
@@ -1061,7 +1021,8 @@ have been gone since last remote command execution. A value of t
would require an immediate reread during filename completion, nil
means to use always cached values for the directory contents."
:group 'tramp
- :type '(choice (const nil) (const t) integer))
+ :type '(choice (const nil) (const t) integer)
+ :require 'tramp)
;;; Internal Variables:
@@ -1077,14 +1038,15 @@ means to use always cached values for the directory contents."
(defvar tramp-current-connection nil
"Last connection timestamp.")
-;;;###autoload
(defconst tramp-completion-file-name-handler-alist
- '((file-name-all-completions . tramp-completion-handle-file-name-all-completions)
+ '((expand-file-name . tramp-completion-handle-expand-file-name)
+ (file-name-all-completions
+ . tramp-completion-handle-file-name-all-completions)
(file-name-completion . tramp-completion-handle-file-name-completion))
"Alist of completion handler functions.
-Used for file names matching `tramp-file-name-regexp'. Operations
-not mentioned here will be handled by Tramp's file name handler
-functions, or the normal Emacs functions.")
+Used for file names matching `tramp-completion-file-name-regexp'.
+Operations not mentioned here will be handled by Tramp's file
+name handler functions, or the normal Emacs functions.")
;; Handlers for foreign methods, like FTP or SMB, shall be plugged here.
;;;###tramp-autoload
@@ -1095,12 +1057,6 @@ calling HANDLER.")
;;; Internal functions which must come first:
-(defsubst tramp-user-error (vec-or-proc format &rest args)
- "Signal a pilot error."
- (apply
- 'tramp-error vec-or-proc
- (if (fboundp 'user-error) 'user-error 'error) format args))
-
;; Conversion functions between external representation and
;; internal data structure. Convenience functions for internal
;; data structure.
@@ -1111,11 +1067,10 @@ If VEC is a vector, check first in connection properties.
Afterwards, check in `tramp-methods'. If the `tramp-methods'
entry does not exist, return nil."
(let ((hash-entry
- (tramp-compat-replace-regexp-in-string
- "^tramp-" "" (symbol-name param))))
+ (replace-regexp-in-string "^tramp-" "" (symbol-name param))))
(if (tramp-connection-property-p vec hash-entry)
;; We use the cached property.
- (tramp-get-connection-property vec hash-entry nil)
+ (tramp-get-connection-property vec hash-entry nil)
;; Use the static value from `tramp-methods'.
(let ((methods-entry
(assoc param (assoc (tramp-file-name-method vec) tramp-methods))))
@@ -1178,33 +1133,33 @@ entry does not exist, return nil."
(defun tramp-file-name-port (vec)
"Return the port number of VEC."
(save-match-data
- (let ((method (tramp-file-name-method vec))
- (host (tramp-file-name-host vec)))
+ (let ((host (tramp-file-name-host vec)))
(or (and (stringp host)
(string-match tramp-host-with-port-regexp host)
(string-to-number (match-string 2 host)))
(tramp-get-method-parameter vec 'tramp-default-port)))))
+;; The localname can be quoted with "/:". Extract this.
+(defun tramp-file-name-unquote-localname (vec)
+ "Return unquoted localname component of VEC."
+ (tramp-compat-file-name-unquote (tramp-file-name-localname vec)))
+
;;;###tramp-autoload
(defun tramp-tramp-file-p (name)
"Return t if NAME is a string with Tramp file name syntax."
(save-match-data
(and (stringp name)
+ ;; No "/:" and "/c:". This is not covered by `tramp-file-name-regexp'.
+ (not (string-match
+ (if (memq system-type '(cygwin windows-nt))
+ "^/[[:alpha:]]?:" "^/:")
+ name))
(string-match tramp-file-name-regexp name))))
-;; Obsoleted with Tramp 2.2.7.
-(defconst tramp-obsolete-methods
- '("ssh1" "ssh2" "scp1" "scp2" "scpc" "rsyncc" "plink1")
- "Obsolete methods.")
-
-(defvar tramp-warned-obsolete-methods nil
- "Which methods the user has been warned to be obsolete.")
-
(defun tramp-find-method (method user host)
"Return the right method string to use.
This is METHOD, if non-nil. Otherwise, do a lookup in
-`tramp-default-method-alist'. It maps also obsolete methods to
-their replacement."
+`tramp-default-method-alist'."
(let ((result
(or method
(let ((choices tramp-default-method-alist)
@@ -1217,24 +1172,10 @@ their replacement."
(setq choices nil)))
lmethod)
tramp-default-method)))
- ;; This is needed for a transition period only.
- (when (member result tramp-obsolete-methods)
- (unless (member result tramp-warned-obsolete-methods)
- (if noninteractive
- (warn "Method %s is obsolete, using %s"
- result (substring result 0 -1))
- (unless (y-or-n-p (format "Method \"%s\" is obsolete, use \"%s\"? "
- result (substring result 0 -1)))
- (tramp-user-error nil "Method \"%s\" not supported" result)))
- (add-to-list 'tramp-warned-obsolete-methods result))
- ;; This works with the current set of `tramp-obsolete-methods'.
- ;; Must be improved, if their are more sophisticated replacements.
- (setq result (substring result 0 -1)))
- ;; We must mark, whether a default value has been used. Not
- ;; applicable for XEmacs.
- (if (or method (null result) (null (functionp 'propertize)))
+ ;; We must mark, whether a default value has been used.
+ (if (or method (null result))
result
- (tramp-compat-funcall 'propertize result 'tramp-default t))))
+ (propertize result 'tramp-default t))))
(defun tramp-find-user (method user host)
"Return the right user string to use.
@@ -1252,11 +1193,10 @@ This is USER, if non-nil. Otherwise, do a lookup in
(setq choices nil)))
luser)
tramp-default-user)))
- ;; We must mark, whether a default value has been used. Not
- ;; applicable for XEmacs.
- (if (or user (null result) (null (functionp 'propertize)))
+ ;; We must mark, whether a default value has been used.
+ (if (or user (null result))
result
- (tramp-compat-funcall 'propertize result 'tramp-default t))))
+ (propertize result 'tramp-default t))))
(defun tramp-find-host (method user host)
"Return the right host string to use.
@@ -1281,13 +1221,14 @@ This is HOST, if non-nil. Otherwise, it is `tramp-default-host'."
(methods (mapcar 'car tramp-methods)))
(when (and method (not (member method methods)))
(tramp-cleanup-connection vec)
- (tramp-user-error vec "Unknown method \"%s\"" method))
+ (tramp-compat-user-error vec "Unknown method \"%s\"" method))
(when (and (equal tramp-syntax 'ftp) host
(or (null method) (get-text-property 0 'tramp-default method))
(or (null user) (get-text-property 0 'tramp-default user))
(member host methods))
(tramp-cleanup-connection vec)
- (tramp-user-error vec "Host name must not match method \"%s\"" host))))
+ (tramp-compat-user-error
+ vec "Host name must not match method \"%s\"" host))))
(defun tramp-dissect-file-name (name &optional nodefault)
"Return a `tramp-file-name' structure.
@@ -1296,8 +1237,9 @@ localname (file name on remote host) and hop. If NODEFAULT is
non-nil, the file name parts are not expanded to their default
values."
(save-match-data
+ (unless (tramp-tramp-file-p name)
+ (tramp-compat-user-error nil "Not a Tramp file name: \"%s\"" name))
(let ((match (string-match (nth 0 tramp-file-name-structure) name)))
- (unless match (tramp-user-error nil "Not a Tramp file name: \"%s\"" name))
(let ((method (match-string (nth 1 tramp-file-name-structure) name))
(user (match-string (nth 2 tramp-file-name-structure) name))
(host (match-string (nth 3 tramp-file-name-structure) name))
@@ -1318,9 +1260,6 @@ values."
(defun tramp-buffer-name (vec)
"A name for the connection buffer VEC."
- ;; We must use `tramp-file-name-real-host', because for gateway
- ;; methods the default port will be expanded later on, which would
- ;; tamper the name.
(let ((method (tramp-file-name-method vec))
(user (tramp-file-name-user vec))
(host (tramp-file-name-real-host vec)))
@@ -1365,6 +1304,11 @@ necessary only. This function will be used in file name completion."
"Get the connection buffer to be used for VEC."
(or (get-buffer (tramp-buffer-name vec))
(with-current-buffer (get-buffer-create (tramp-buffer-name vec))
+ ;; We use the existence of connection property "process-buffer"
+ ;; as indication, whether a connection is active.
+ (tramp-set-connection-property
+ vec "process-buffer"
+ (tramp-get-connection-property vec "process-buffer" nil))
(setq buffer-undo-list t)
(setq default-directory
(tramp-make-tramp-file-name
@@ -1394,11 +1338,17 @@ In case a second asynchronous communication has been started, it is different
from the default one."
(get-process (tramp-get-connection-name vec)))
+(defun tramp-set-connection-local-variables (vec)
+ "Set connection-local variables in the connection buffer used for VEC.
+If connection-local variables are not supported by this Emacs
+version, the function does nothing."
+ ;; `tramp-get-connection-buffer' sets proper `default-directory'."
+ (with-current-buffer (tramp-get-connection-buffer vec)
+ ;; `hack-connection-local-variables-apply' exists since Emacs 26.1.
+ (tramp-compat-funcall 'hack-connection-local-variables-apply)))
+
(defun tramp-debug-buffer-name (vec)
"A name for the debug buffer for VEC."
- ;; We must use `tramp-file-name-real-host', because for gateway
- ;; methods the default port will be expanded later on, which would
- ;; tamper the name.
(let ((method (tramp-file-name-method vec))
(user (tramp-file-name-user vec))
(host (tramp-file-name-real-host vec)))
@@ -1447,8 +1397,7 @@ ARGUMENTS to actually emit the message (if applicable)."
(when (bobp)
(insert
(format
- ";; %sEmacs: %s Tramp: %s -*- mode: outline; -*-"
- (if (featurep 'sxemacs) "SX" (if (featurep 'xemacs) "X" "GNU "))
+ ";; Emacs: %s Tramp: %s -*- mode: outline; -*-"
emacs-version tramp-version))
(when (>= tramp-verbose 10)
(insert
@@ -1481,13 +1430,12 @@ ARGUMENTS to actually emit the message (if applicable)."
'("tramp-backtrace"
"tramp-compat-condition-case-unless-debug"
"tramp-compat-funcall"
- "tramp-compat-with-temp-message"
+ "tramp-compat-user-error"
"tramp-condition-case-unless-debug"
"tramp-debug-message"
"tramp-error"
"tramp-error-with-buffer"
- "tramp-message"
- "tramp-user-error")
+ "tramp-message")
t)
"$")
fn)))
@@ -1651,14 +1599,14 @@ If VAR is nil, then we bind `v' to the structure and `method', `user',
(put 'with-parsed-tramp-file-name 'lisp-indent-function 2)
(put 'with-parsed-tramp-file-name 'edebug-form-spec '(form symbolp body))
-(tramp-compat-font-lock-add-keywords
- 'emacs-lisp-mode '("\\<with-parsed-tramp-file-name\\>"))
+(font-lock-add-keywords 'emacs-lisp-mode '("\\<with-parsed-tramp-file-name\\>"))
(defun tramp-progress-reporter-update (reporter &optional value)
+ "Report progress of an operation for Tramp."
(let* ((parameters (cdr reporter))
(message (aref parameters 3)))
(when (string-match message (or (current-message) ""))
- (tramp-compat-funcall 'progress-reporter-update reporter value))))
+ (progress-reporter-update reporter value))))
(defmacro with-tramp-progress-reporter (vec level message &rest body)
"Executes BODY, spinning a progress reporter with MESSAGE.
@@ -1675,19 +1623,18 @@ without a visible progress reporter."
;; Display only when there is a minimum level.
(<= ,level (min tramp-verbose 3)))
(ignore-errors
- (let ((pr (tramp-compat-funcall
- #'make-progress-reporter ,message)))
+ (let ((pr (make-progress-reporter ,message nil nil)))
(when pr
- (run-at-time 3 0.1
- #'tramp-progress-reporter-update pr)))))))
+ (run-at-time
+ 3 0.1 #'tramp-progress-reporter-update pr)))))))
(unwind-protect
;; Execute the body.
(prog1 (progn ,@body) (setq cookie "done"))
;; Stop progress reporter.
- (if tm (tramp-compat-funcall 'cancel-timer tm))
+ (if tm (cancel-timer tm))
(tramp-message ,vec ,level "%s...%s" ,message cookie)))))
-(tramp-compat-font-lock-add-keywords
+(font-lock-add-keywords
'emacs-lisp-mode '("\\<with-tramp-progress-reporter\\>"))
(defmacro with-tramp-file-property (vec file property &rest body)
@@ -1706,8 +1653,7 @@ FILE must be a local file name on a connection identified via VEC."
(put 'with-tramp-file-property 'lisp-indent-function 3)
(put 'with-tramp-file-property 'edebug-form-spec t)
-(tramp-compat-font-lock-add-keywords
- 'emacs-lisp-mode '("\\<with-tramp-file-property\\>"))
+(font-lock-add-keywords 'emacs-lisp-mode '("\\<with-tramp-file-property\\>"))
(defmacro with-tramp-connection-property (key property &rest body)
"Check in Tramp for property PROPERTY, otherwise executes BODY and set."
@@ -1722,7 +1668,7 @@ FILE must be a local file name on a connection identified via VEC."
(put 'with-tramp-connection-property 'lisp-indent-function 2)
(put 'with-tramp-connection-property 'edebug-form-spec t)
-(tramp-compat-font-lock-add-keywords
+(font-lock-add-keywords
'emacs-lisp-mode '("\\<with-tramp-connection-property\\>"))
(defun tramp-drop-volume-letter (name)
@@ -1732,9 +1678,13 @@ locally on a remote file name. When the local system is a W32 system
but the remote system is Unix, this introduces a superfluous drive
letter into the file name. This function removes it."
(save-match-data
- (if (string-match "\\`[a-zA-Z]:/" name)
- (replace-match "/" nil t name)
- name)))
+ (funcall
+ (if (tramp-compat-file-name-quoted-p name)
+ 'tramp-compat-file-name-quote 'identity)
+ (let ((name (tramp-compat-file-name-unquote name)))
+ (if (string-match "\\`[a-zA-Z]:/" name)
+ (replace-match "/" nil t name)
+ name)))))
;;; Config Manipulation Functions:
@@ -1787,16 +1737,17 @@ Example:
(defun tramp-get-completion-function (method)
"Returns a list of completion functions for METHOD.
For definition of that list see `tramp-set-completion-function'."
- (cons
- ;; Hosts visited once shall be remembered.
- `(tramp-parse-connection-properties ,method)
+ (append
+ `(;; Default settings are taken into account.
+ (tramp-parse-default-user-host ,method)
+ ;; Hosts visited once shall be remembered.
+ (tramp-parse-connection-properties ,method))
;; The method related defaults.
(cdr (assoc method tramp-completion-function-alist))))
;;; Fontification of `read-file-name':
-;; rfn-eshadow.el is part of Emacs 22. It is autoloaded.
(defvar tramp-rfn-eshadow-overlay)
(make-variable-buffer-local 'tramp-rfn-eshadow-overlay)
@@ -1806,28 +1757,22 @@ Adds another overlay hiding filename parts according to Tramp's
special handling of `substitute-in-file-name'."
(when (symbol-value 'minibuffer-completing-file-name)
(setq tramp-rfn-eshadow-overlay
- (tramp-compat-funcall
- 'make-overlay
- (tramp-compat-funcall 'minibuffer-prompt-end)
- (tramp-compat-funcall 'minibuffer-prompt-end)))
+ (make-overlay (minibuffer-prompt-end) (minibuffer-prompt-end)))
;; Copy rfn-eshadow-overlay properties.
- (let ((props (tramp-compat-funcall
- 'overlay-properties (symbol-value 'rfn-eshadow-overlay))))
+ (let ((props (overlay-properties (symbol-value 'rfn-eshadow-overlay))))
(while props
;; The `field' property prevents correct minibuffer
;; completion; we exclude it.
(if (not (eq (car props) 'field))
- (tramp-compat-funcall
- 'overlay-put tramp-rfn-eshadow-overlay (pop props) (pop props))
+ (overlay-put tramp-rfn-eshadow-overlay (pop props) (pop props))
(pop props) (pop props))))))
-(when (boundp 'rfn-eshadow-setup-minibuffer-hook)
- (add-hook 'rfn-eshadow-setup-minibuffer-hook
- 'tramp-rfn-eshadow-setup-minibuffer)
- (add-hook 'tramp-unload-hook
- (lambda ()
- (remove-hook 'rfn-eshadow-setup-minibuffer-hook
- 'tramp-rfn-eshadow-setup-minibuffer))))
+(add-hook 'rfn-eshadow-setup-minibuffer-hook
+ 'tramp-rfn-eshadow-setup-minibuffer)
+(add-hook 'tramp-unload-hook
+ (lambda ()
+ (remove-hook 'rfn-eshadow-setup-minibuffer-hook
+ 'tramp-rfn-eshadow-setup-minibuffer)))
(defconst tramp-rfn-eshadow-update-overlay-regexp
(format "[^%s/~]*\\(/\\|~\\)" tramp-postfix-host-format))
@@ -1839,15 +1784,13 @@ This is intended to be used as a minibuffer `post-command-hook' for
been set up by `rfn-eshadow-setup-minibuffer'."
;; In remote files name, there is a shadowing just for the local part.
(ignore-errors
- (let ((end (or (tramp-compat-funcall
- 'overlay-end (symbol-value 'rfn-eshadow-overlay))
- (tramp-compat-funcall 'minibuffer-prompt-end)))
+ (let ((end (or (overlay-end (symbol-value 'rfn-eshadow-overlay))
+ (minibuffer-prompt-end)))
;; We do not want to send any remote command.
(non-essential t))
(when
(tramp-tramp-file-p
- (tramp-compat-funcall
- 'buffer-substring-no-properties end (point-max)))
+ (buffer-substring-no-properties end (point-max)))
(save-excursion
(save-restriction
(narrow-to-region
@@ -1859,17 +1802,15 @@ been set up by `rfn-eshadow-setup-minibuffer'."
(let ((rfn-eshadow-overlay tramp-rfn-eshadow-overlay)
(rfn-eshadow-update-overlay-hook nil)
file-name-handler-alist)
- (tramp-compat-funcall
- 'move-overlay rfn-eshadow-overlay (point-max) (point-max))
- (tramp-compat-funcall 'rfn-eshadow-update-overlay))))))))
-
-(when (boundp 'rfn-eshadow-update-overlay-hook)
- (add-hook 'rfn-eshadow-update-overlay-hook
- 'tramp-rfn-eshadow-update-overlay)
- (add-hook 'tramp-unload-hook
- (lambda ()
- (remove-hook 'rfn-eshadow-update-overlay-hook
- 'tramp-rfn-eshadow-update-overlay))))
+ (move-overlay rfn-eshadow-overlay (point-max) (point-max))
+ (rfn-eshadow-update-overlay))))))))
+
+(add-hook 'rfn-eshadow-update-overlay-hook
+ 'tramp-rfn-eshadow-update-overlay)
+(add-hook 'tramp-unload-hook
+ (lambda ()
+ (remove-hook 'rfn-eshadow-update-overlay-hook
+ 'tramp-rfn-eshadow-update-overlay)))
;; Inodes don't exist for some file systems. Therefore we must
;; generate virtual ones. Used in `find-buffer-visiting'. The method
@@ -1892,12 +1833,13 @@ been set up by `rfn-eshadow-setup-minibuffer'."
If the file modes of FILENAME cannot be determined, return the
value of `default-file-modes', without execute permissions."
(or (file-modes filename)
- (logand (default-file-modes) (tramp-compat-octal-to-decimal "0666"))))
+ (logand (default-file-modes) (string-to-number "0666" 8))))
(defun tramp-replace-environment-variables (filename)
"Replace environment variables in FILENAME.
Return the string with the replaced variables."
(or (ignore-errors
+ ;; Optional arg has been introduced with Emacs 24 (?).
(tramp-compat-funcall 'substitute-env-vars filename 'only-defined))
;; We need an own implementation.
(save-match-data
@@ -1912,35 +1854,6 @@ Return the string with the replaced variables."
t nil filename)))
filename))))
-;; In XEmacs, electricity is implemented via a key map for ?/ and ?~,
-;; which calls corresponding functions (see minibuf.el).
-(when (fboundp 'minibuffer-electric-separator)
- (mapc
- (lambda (x)
- (eval
- `(defadvice ,x
- (around ,(intern (format "tramp-advice-%s" x)) activate)
- "Invoke `substitute-in-file-name' for Tramp files."
- (if (and (symbol-value 'minibuffer-electric-file-name-behavior)
- (tramp-tramp-file-p (buffer-substring)))
- ;; We don't need to handle `last-input-event', because
- ;; due to the key map we know it must be ?/ or ?~.
- (let ((s (concat (buffer-substring (point-min) (point))
- (string last-command-char))))
- (delete-region (point-min) (point))
- (insert (substitute-in-file-name s))
- (setq ad-return-value last-command-char))
- ad-do-it)))
- (eval
- `(add-hook
- 'tramp-unload-hook
- (lambda ()
- (ad-remove-advice ',x 'around ',(intern (format "tramp-advice-%s" x)))
- (ad-activate ',x)))))
-
- '(minibuffer-electric-separator
- minibuffer-electric-tilde)))
-
(defun tramp-find-file-name-coding-system-alist (filename tmpname)
"Like `find-operation-coding-system' for Tramp filenames.
Tramp's `insert-file-contents' and `write-region' work over
@@ -2000,49 +1913,37 @@ ARGS are the arguments OPERATION has been called with."
(cond
;; FILE resp DIRECTORY.
((member operation
- (list 'access-file 'byte-compiler-base-file-name 'delete-directory
- 'delete-file 'diff-latest-backup-file 'directory-file-name
- 'directory-files 'directory-files-and-attributes
- 'dired-compress-file 'dired-uncache
- 'file-accessible-directory-p 'file-attributes
- 'file-directory-p 'file-executable-p 'file-exists-p
- 'file-local-copy 'file-modes
- 'file-name-as-directory 'file-name-directory
- 'file-name-nondirectory 'file-name-sans-versions
- 'file-ownership-preserved-p 'file-readable-p
- 'file-regular-p 'file-remote-p 'file-symlink-p 'file-truename
- 'file-writable-p 'find-backup-file-name 'find-file-noselect
- 'get-file-buffer 'insert-directory 'insert-file-contents
- 'load 'make-directory 'make-directory-internal
- 'set-file-modes 'substitute-in-file-name
- 'unhandled-file-name-directory 'vc-registered
- ;; Emacs 22+ only.
- 'set-file-times
- ;; Emacs 24+ only.
- 'file-acl 'file-notify-add-watch
- 'file-selinux-context 'set-file-acl 'set-file-selinux-context
- ;; XEmacs only.
- 'abbreviate-file-name 'create-file-buffer
- 'dired-file-modtime 'dired-make-compressed-filename
- 'dired-recursive-delete-directory 'dired-set-file-modtime
- 'dired-shell-unhandle-file-name 'dired-uucode-file
- 'insert-file-contents-literally 'make-temp-name 'recover-file
- 'vm-imap-check-mail 'vm-pop-check-mail 'vm-spool-check-mail))
+ '(access-file byte-compiler-base-file-name delete-directory
+ delete-file diff-latest-backup-file directory-file-name
+ directory-files directory-files-and-attributes
+ dired-compress-file dired-uncache
+ file-accessible-directory-p file-attributes
+ file-directory-p file-executable-p file-exists-p
+ file-local-copy file-modes
+ file-name-as-directory file-name-directory
+ file-name-nondirectory file-name-sans-versions
+ file-ownership-preserved-p file-readable-p
+ file-regular-p file-remote-p file-symlink-p file-truename
+ file-writable-p find-backup-file-name find-file-noselect
+ get-file-buffer insert-directory insert-file-contents
+ load make-directory make-directory-internal
+ set-file-modes set-file-times substitute-in-file-name
+ unhandled-file-name-directory vc-registered
+ ;; Emacs 24+ only.
+ file-acl file-notify-add-watch file-selinux-context
+ set-file-acl set-file-selinux-context
+ ;; Emacs 26+ only.
+ file-name-case-insensitive-p))
(if (file-name-absolute-p (nth 0 args))
(nth 0 args)
(expand-file-name (nth 0 args))))
;; FILE DIRECTORY resp FILE1 FILE2.
((member operation
- (list 'add-name-to-file 'copy-file 'expand-file-name
- 'file-name-all-completions 'file-name-completion
- 'file-newer-than-file-p 'make-symbolic-link 'rename-file
- ;; Emacs 23+ only.
- 'copy-directory
- ;; Emacs 24+ only.
- 'file-equal-p 'file-in-directory-p
- ;; XEmacs only.
- 'dired-make-relative-symlink
- 'vm-imap-move-mail 'vm-pop-move-mail 'vm-spool-move-mail))
+ '(add-name-to-file copy-directory copy-file expand-file-name
+ file-name-all-completions file-name-completion
+ file-newer-than-file-p make-symbolic-link rename-file
+ ;; Emacs 24+ only.
+ file-equal-p file-in-directory-p))
(save-match-data
(cond
((tramp-tramp-file-p (nth 0 args)) (nth 0 args))
@@ -2053,35 +1954,30 @@ ARGS are the arguments OPERATION has been called with."
(nth 2 args))
;; BUFFER.
((member operation
- (list 'set-visited-file-modtime 'verify-visited-file-modtime
- ;; Emacs 22+ only.
- 'make-auto-save-file-name
- ;; XEmacs only.
- 'backup-buffer))
+ '(make-auto-save-file-name
+ set-visited-file-modtime verify-visited-file-modtime))
(buffer-file-name
(if (bufferp (nth 0 args)) (nth 0 args) (current-buffer))))
;; COMMAND.
((member operation
- (list ;; not in Emacs 23+.
- 'dired-call-process
- ;; Emacs only.
- 'shell-command
- ;; Emacs 22+ only.
- 'process-file
- ;; Emacs 23+ only.
- 'start-file-process
- ;; XEmacs only.
- 'dired-print-file 'dired-shell-call-process))
+ '(process-file shell-command start-file-process
+ ;; Emacs 26+ only.
+ make-nearby-temp-file temporary-file-directory))
default-directory)
;; PROC.
- ((member operation (list 'file-notify-rm-watch 'file-notify-valid-p))
+ ((member operation
+ '(;; Emacs 24+ only.
+ file-notify-rm-watch
+ ;; Emacs 25+ only.
+ file-notify-valid-p))
(when (processp (nth 0 args))
(with-current-buffer (process-buffer (nth 0 args))
default-directory)))
;; Unknown file primitive.
(t (error "unknown file I/O primitive: %s" operation))))
-(defun tramp-find-foreign-file-name-handler (filename)
+(defun tramp-find-foreign-file-name-handler
+ (filename &optional operation completion)
"Return foreign file name handler if exists."
(when (tramp-tramp-file-p filename)
(let ((v (tramp-dissect-file-name filename t))
@@ -2089,11 +1985,17 @@ ARGS are the arguments OPERATION has been called with."
elt res)
;; When we are not fully sure that filename completion is safe,
;; we should not return a handler.
- (when (or (tramp-file-name-method v) (tramp-file-name-user v)
+ (when (or (not completion)
+ (tramp-file-name-method v) (tramp-file-name-user v)
(and (tramp-file-name-host v)
(not (member (tramp-file-name-host v)
(mapcar 'car tramp-methods))))
- (not (tramp-completion-mode-p)))
+ ;; Some operations are safe by default.
+ (member
+ operation
+ '(file-name-as-directory
+ file-name-directory
+ file-name-nondirectory)))
(while handler
(setq elt (car handler)
handler (cdr handler))
@@ -2115,19 +2017,20 @@ ARGS are the arguments OPERATION has been called with."
(defun tramp-file-name-handler (operation &rest args)
"Invoke Tramp file name handler.
Falls back to normal file name handler if no Tramp file name handler exists."
- (if tramp-mode
- (save-match-data
- (let* ((filename
- (tramp-replace-environment-variables
- (apply 'tramp-file-name-for-operation operation args)))
- (completion (tramp-completion-mode-p))
- (foreign (tramp-find-foreign-file-name-handler filename)))
- (with-parsed-tramp-file-name filename nil
- ;; Call the backend function.
- (if foreign
- (tramp-condition-case-unless-debug err
- (let ((sf (symbol-function foreign))
- result)
+ (let ((filename (apply 'tramp-file-name-for-operation operation args)))
+ (if (and tramp-mode (tramp-tramp-file-p filename))
+ (save-match-data
+ (let* ((filename (tramp-replace-environment-variables filename))
+ (completion (tramp-completion-mode-p))
+ (foreign
+ (tramp-find-foreign-file-name-handler
+ filename operation completion))
+ result)
+ (with-parsed-tramp-file-name filename nil
+ ;; Call the backend function.
+ (if foreign
+ (tramp-condition-case-unless-debug err
+ (let ((sf (symbol-function foreign)))
;; Some packages set the default directory to a
;; remote path, before respective Tramp packages
;; are already loaded. This results in
@@ -2164,38 +2067,44 @@ Falls back to normal file name handler if no Tramp file name handler exists."
(tramp-run-real-handler operation args)))
(t result)))
- ;; Trace that somebody has interrupted the operation.
- ((debug quit)
- (let (tramp-message-show-message)
- (tramp-message
- v 1 "Interrupt received in operation %s"
- (cons operation args)))
- ;; Propagate the quit signal.
- (signal (car err) (cdr err)))
-
- ;; When we are in completion mode, some failed
- ;; operations shall return at least a default value
- ;; in order to give the user a chance to correct the
- ;; file name in the minibuffer.
- ;; In order to get a full backtrace, one could apply
- ;; (setq tramp-debug-on-error t)
- (error
- (cond
- ((and completion (zerop (length localname))
- (memq operation '(file-exists-p file-directory-p)))
- t)
- ((and completion (zerop (length localname))
- (memq operation
- '(expand-file-name file-name-as-directory)))
- filename)
- ;; Propagate the error.
- (t (signal (car err) (cdr err))))))
-
- ;; Nothing to do for us.
- (tramp-run-real-handler operation args)))))
-
- ;; When `tramp-mode' is not enabled, we don't do anything.
- (tramp-run-real-handler operation args)))
+ ;; Trace that somebody has interrupted the operation.
+ ((debug quit)
+ (let (tramp-message-show-message)
+ (tramp-message
+ v 1 "Interrupt received in operation %s"
+ (cons operation args)))
+ ;; Propagate the quit signal.
+ (signal (car err) (cdr err)))
+
+ ;; When we are in completion mode, some failed
+ ;; operations shall return at least a default
+ ;; value in order to give the user a chance to
+ ;; correct the file name in the minibuffer.
+ ;; In order to get a full backtrace, one could apply
+ ;; (setq tramp-debug-on-error t)
+ (error
+ (cond
+ ((and completion (zerop (length localname))
+ (memq operation '(file-exists-p file-directory-p)))
+ t)
+ ((and completion (zerop (length localname))
+ (memq operation
+ '(expand-file-name file-name-as-directory)))
+ filename)
+ ;; Propagate the error.
+ (t (signal (car err) (cdr err))))))
+
+ ;; Nothing to do for us. However, since we are in
+ ;; `tramp-mode', we must suppress the volume letter on
+ ;; MS Windows.
+ (setq result (tramp-run-real-handler operation args))
+ (if (stringp result)
+ (tramp-drop-volume-letter result)
+ result)))))
+
+ ;; When `tramp-mode' is not enabled, or the file name is quoted,
+ ;; we don't do anything.
+ (tramp-run-real-handler operation args))))
;; In Emacs, there is some concurrency due to timers. If a timer
;; interrupts Tramp and wishes to use the same connection buffer as
@@ -2224,17 +2133,17 @@ preventing reentrant calls of Tramp.")
Together with `tramp-locked', this implements a locking mechanism
preventing reentrant calls of Tramp.")
-;;;###autoload
-(progn (defun tramp-completion-file-name-handler (operation &rest args)
+;; Avoid recursive loading of tramp.el.
+;;;###autoload(defun tramp-completion-file-name-handler (operation &rest args)
+;;;###autoload (tramp-completion-run-real-handler operation args))
+
+(defun tramp-completion-file-name-handler (operation &rest args)
"Invoke Tramp file name completion handler.
Falls back to normal file name handler if no Tramp file name handler exists."
- ;; We bind `directory-sep-char' here for XEmacs on Windows, which
- ;; would otherwise use backslash.
- (let ((directory-sep-char ?/)
- (fn (assoc operation tramp-completion-file-name-handler-alist)))
+ (let ((fn (assoc operation tramp-completion-file-name-handler-alist)))
(if (and
;; When `tramp-mode' is not enabled, we don't do anything.
- fn tramp-mode
+ fn tramp-mode (tramp-completion-mode-p)
;; For other syntaxes than `sep', the regexp matches many common
;; situations where the user doesn't actually want to use Tramp.
;; So to avoid autoloading Tramp after typing just "/s", we
@@ -2242,8 +2151,7 @@ Falls back to normal file name handler if no Tramp file name handler exists."
;; indicated his interest in using a fancier completion system.
(or (eq tramp-syntax 'sep)
(featurep 'tramp) ;; If it's loaded, we may as well use it.
- ;; `partial-completion-mode' does not exist in XEmacs.
- ;; It is obsoleted with Emacs 24.1.
+ ;; `partial-completion-mode' is obsoleted with Emacs 24.1.
(and (boundp 'partial-completion-mode)
(symbol-value 'partial-completion-mode))
;; FIXME: These may have been loaded even if the user never
@@ -2251,14 +2159,13 @@ Falls back to normal file name handler if no Tramp file name handler exists."
(featurep 'ido)
(featurep 'icicles)))
(save-match-data (apply (cdr fn) args))
- (tramp-completion-run-real-handler operation args)))))
+ (tramp-completion-run-real-handler operation args))))
;;;###autoload
(progn (defun tramp-autoload-file-name-handler (operation &rest args)
"Load Tramp file name handler, and perform OPERATION."
- ;; Avoid recursive loading of tramp.el. `temporary-file-directory'
- ;; does not exist in XEmacs, so we must use something else.
- (let ((default-directory "/"))
+ ;; Avoid recursive loading of tramp.el.
+ (let ((default-directory temporary-file-directory))
(load "tramp" nil t))
(apply operation args)))
@@ -2292,6 +2199,10 @@ Falls back to normal file name handler if no Tramp file name handler exists."
tramp-autoload-file-name-handler))
(let ((a1 (rassq fnh file-name-handler-alist)))
(setq file-name-handler-alist (delq a1 file-name-handler-alist))))
+ ;; The initial value of `tramp-file-name-regexp' is too simple
+ ;; minded, but we cannot give it the real value in the autoload
+ ;; pattern. See Bug#24889.
+ (setq tramp-file-name-regexp (car tramp-file-name-structure))
;; Add the handlers.
(add-to-list 'file-name-handler-alist
(cons tramp-file-name-regexp 'tramp-file-name-handler))
@@ -2332,6 +2243,7 @@ Falls back to normal file name handler if no Tramp file name handler exists."
;;;###autoload
(defun tramp-unload-file-name-handlers ()
+ "Unload Tramp file name handlers from `file-name-handler-alist'."
(setq file-name-handler-alist
(delete (rassoc 'tramp-file-name-handler
file-name-handler-alist)
@@ -2343,6 +2255,7 @@ Falls back to normal file name handler if no Tramp file name handler exists."
;;; File name handler functions for completion mode:
+;;;###autoload
(defvar tramp-completion-mode nil
"If non-nil, external packages signal that they are in file name completion.
@@ -2361,15 +2274,13 @@ should never be set globally, the intention is to let-bind it.")
;; variable. On the other hand, those files shouldn't have partial
;; Tramp file name syntax. Maybe another variable should be introduced
;; overwriting this check in such cases. Or we change Tramp file name
-;; syntax in order to avoid ambiguities, like in XEmacs ...
-;;;###tramp-autoload
+;; syntax in order to avoid ambiguities.
(defun tramp-completion-mode-p ()
"Check, whether method / user name / host name completion is active."
(or
;; Signal from outside. `non-essential' has been introduced in Emacs 24.
(and (boundp 'non-essential) (symbol-value 'non-essential))
tramp-completion-mode
- ;; Emacs.
(equal last-input-event 'tab)
(and (natnump last-input-event)
(or
@@ -2377,40 +2288,37 @@ should never be set globally, the intention is to let-bind it.")
(equal last-input-event ?\t)
(and (not (event-modifiers last-input-event))
(or (equal last-input-event ?\?)
- (equal last-input-event ?\ )))))
- ;; XEmacs.
- (and (featurep 'xemacs)
- ;; `last-input-event' might be nil.
- (not (null last-input-event))
- ;; `last-input-event' may have no character approximation.
- (tramp-compat-funcall 'event-to-character last-input-event)
- (or
- ;; ?\t has event-modifier 'control.
- (equal
- (tramp-compat-funcall 'event-to-character last-input-event) ?\t)
- (and (not (event-modifiers last-input-event))
- (or (equal
- (tramp-compat-funcall 'event-to-character last-input-event)
- ?\?)
- (equal
- (tramp-compat-funcall 'event-to-character last-input-event)
- ?\ )))))))
+ (equal last-input-event ?\ )))))))
(defun tramp-connectable-p (filename)
"Check, whether it is possible to connect the remote host w/o side-effects.
This is true, if either the remote host is already connected, or if we are
not in completion mode."
- (and (tramp-tramp-file-p filename)
- (with-parsed-tramp-file-name filename nil
+ (let (tramp-verbose)
+ (and (tramp-tramp-file-p filename)
(or (not (tramp-completion-mode-p))
- (let* ((tramp-verbose 0)
- (p (tramp-get-connection-process v)))
- (and p (processp p) (memq (process-status p) '(run open))))))))
+ (tramp-compat-process-live-p
+ (tramp-get-connection-process
+ (tramp-dissect-file-name filename)))))))
+
+(defun tramp-completion-handle-expand-file-name (name &optional dir)
+ "Like `expand-file-name' for Tramp files."
+ (if (tramp-completion-mode-p)
+ (progn
+ ;; If DIR is not given, use `default-directory' or "/".
+ (setq dir (or dir default-directory "/"))
+ ;; Unless NAME is absolute, concat DIR and NAME.
+ (unless (file-name-absolute-p name)
+ (setq name (concat (file-name-as-directory dir) name)))
+ ;; Return NAME.
+ name)
+
+ (tramp-completion-run-real-handler
+ 'expand-file-name (list name dir))))
;; Method, host name and user name completion.
;; `tramp-completion-dissect-file-name' returns a list of
;; tramp-file-name structures. For all of them we return possible completions.
-;;;###autoload
(defun tramp-completion-handle-file-name-all-completions (filename directory)
"Like `file-name-all-completions' for partial Tramp files."
@@ -2483,7 +2391,6 @@ not in completion mode."
'file-name-all-completions (list (list filename directory)))))))
;; Method, host name and user name completion for a file.
-;;;###autoload
(defun tramp-completion-handle-file-name-completion
(filename directory &optional predicate)
"Like `file-name-completion' for Tramp files."
@@ -2675,6 +2582,12 @@ PARTIAL-USER must match USER, PARTIAL-HOST must match HOST."
(unless (zerop (+ (length user) (length host)))
(tramp-completion-make-tramp-file-name method user host nil)))
+(defun tramp-parse-default-user-host (method)
+ "Return a list of (user host) tuples allowed to access for METHOD.
+This function is added always in `tramp-get-completion-function'
+for all methods. Resulting data are derived from default settings."
+ `((,(tramp-find-user method nil nil) ,(tramp-find-host method nil nil))))
+
;; Generic function.
(defun tramp-parse-group (regexp match-level skip-regexp)
"Return a (user host) tuple allowed to access.
@@ -2781,17 +2694,18 @@ User is always nil."
(tramp-parse-group
(concat "^\\(" tramp-ipv6-regexp "\\|" tramp-host-regexp "\\)") 1 " \t"))
-;; For su-alike methods it would be desirable to return "root@localhost"
-;; as default. Unfortunately, we have no information whether any user name
-;; has been typed already. So we use `tramp-current-user' as indication,
-;; assuming it is set in `tramp-completion-handle-file-name-all-completions'.
;;;###tramp-autoload
(defun tramp-parse-passwd (filename)
"Return a list of (user host) tuples allowed to access.
Host is always \"localhost\"."
- (if (zerop (length tramp-current-user))
- '(("root" nil))
- (tramp-parse-file filename 'tramp-parse-passwd-group)))
+ (with-tramp-connection-property nil "parse-passwd"
+ (if (executable-find "getent")
+ (with-temp-buffer
+ (when (zerop (tramp-call-process nil "getent" nil t nil "passwd"))
+ (goto-char (point-min))
+ (loop while (not (eobp)) collect
+ (tramp-parse-etc-group-group))))
+ (tramp-parse-file filename 'tramp-parse-passwd-group))))
(defun tramp-parse-passwd-group ()
"Return a (user host) tuple allowed to access.
@@ -2804,6 +2718,29 @@ Host is always \"localhost\"."
result))
;;;###tramp-autoload
+(defun tramp-parse-etc-group (filename)
+ "Return a list of (group host) tuples allowed to access.
+Host is always \"localhost\"."
+ (with-tramp-connection-property nil "parse-group"
+ (if (executable-find "getent")
+ (with-temp-buffer
+ (when (zerop (tramp-call-process nil "getent" nil t nil "group"))
+ (goto-char (point-min))
+ (loop while (not (eobp)) collect
+ (tramp-parse-etc-group-group))))
+ (tramp-parse-file filename 'tramp-parse-etc-group-group))))
+
+(defun tramp-parse-etc-group-group ()
+ "Return a (group host) tuple allowed to access.
+Host is always \"localhost\"."
+ (let ((result)
+ (split (split-string (buffer-substring (point) (point-at-eol)) ":")))
+ (when (member (user-login-name) (split-string (nth 3 split) "," 'omit))
+ (setq result (list (nth 0 split) "localhost")))
+ (forward-line 1)
+ result))
+
+;;;###tramp-autoload
(defun tramp-parse-netrc (filename)
"Return a list of (user host) tuples allowed to access.
User may be nil."
@@ -2827,12 +2764,13 @@ User may be nil."
"Return a list of (user host) tuples allowed to access.
User is always nil."
(if (memq system-type '(windows-nt))
- (with-temp-buffer
- (when (zerop (tramp-call-process
- nil "reg" nil t nil "query" registry-or-dirname))
- (goto-char (point-min))
- (loop while (not (eobp)) collect
- (tramp-parse-putty-group registry-or-dirname))))
+ (with-tramp-connection-property nil "parse-putty"
+ (with-temp-buffer
+ (when (zerop (tramp-call-process
+ nil "reg" nil t nil "query" registry-or-dirname))
+ (goto-char (point-min))
+ (loop while (not (eobp)) collect
+ (tramp-parse-putty-group registry-or-dirname)))))
;; UNIX case.
(tramp-parse-shostkeys-sknownhosts
registry-or-dirname (concat "^\\(" tramp-host-regexp "\\)$"))))
@@ -2868,10 +2806,8 @@ User is always nil."
(substring directory 0 -1)
directory)))
-(defun tramp-handle-directory-files
- (directory &optional full match nosort files-only)
+(defun tramp-handle-directory-files (directory &optional full match nosort)
"Like `directory-files' for Tramp files."
- ;; FILES-ONLY is valid for XEmacs only.
(when (file-directory-p directory)
(setq directory (file-name-as-directory (expand-file-name directory)))
(let ((temp (nreverse (file-name-all-completions "" directory)))
@@ -2879,12 +2815,7 @@ User is always nil."
(while temp
(setq item (directory-file-name (pop temp)))
- (when (and (or (null match) (string-match match item))
- (or (null files-only)
- ;; Files only.
- (and (equal files-only t) (file-regular-p item))
- ;; Directories only.
- (file-directory-p item)))
+ (when (or (null match) (string-match match item))
(push (if full (concat directory item) item)
result)))
(if nosort result (sort result 'string<)))))
@@ -2894,15 +2825,14 @@ User is always nil."
"Like `directory-files-and-attributes' for Tramp files."
(mapcar
(lambda (x)
- (cons x (tramp-compat-file-attributes
+ (cons x (file-attributes
(if full x (expand-file-name x directory)) id-format)))
(directory-files directory full match nosort)))
-(defun tramp-handle-dired-uncache (dir &optional dir-p)
+(defun tramp-handle-dired-uncache (dir)
"Like `dired-uncache' for Tramp files."
- ;; DIR-P is valid for XEmacs only.
(with-parsed-tramp-file-name
- (if (or dir-p (file-directory-p dir)) dir (file-name-directory dir)) nil
+ (if (file-directory-p dir) dir (file-name-directory dir)) nil
(tramp-flush-directory-property v localname)))
(defun tramp-handle-file-accessible-directory-p (filename)
@@ -2938,7 +2868,8 @@ User is always nil."
"Like `file-modes' for Tramp files."
(let ((truename (or (file-truename filename) filename)))
(when (file-exists-p truename)
- (tramp-mode-string-to-int (nth 8 (file-attributes truename))))))
+ (tramp-mode-string-to-int
+ (tramp-compat-file-attribute-modes (file-attributes truename))))))
;; Localname manipulation functions that grok Tramp localnames...
(defun tramp-handle-file-name-as-directory (file)
@@ -2946,15 +2877,66 @@ User is always nil."
;; `file-name-as-directory' would be sufficient except localname is
;; the empty string.
(let ((v (tramp-dissect-file-name file t)))
- ;; Run the command on the localname portion only.
+ ;; Run the command on the localname portion only unless we are in
+ ;; completion mode.
(tramp-make-tramp-file-name
(tramp-file-name-method v)
(tramp-file-name-user v)
(tramp-file-name-host v)
- (tramp-run-real-handler
- 'file-name-as-directory (list (or (tramp-file-name-localname v) "")))
+ (if (and (tramp-completion-mode-p)
+ (zerop (length (tramp-file-name-localname v))))
+ ""
+ (tramp-run-real-handler
+ 'file-name-as-directory (list (or (tramp-file-name-localname v) ""))))
(tramp-file-name-hop v))))
+(defun tramp-handle-file-name-case-insensitive-p (filename)
+ "Like `file-name-case-insensitive-p' for Tramp files."
+ ;; We make it a connection property, assuming that all file systems
+ ;; on the remote host behave similar. This might be wrong for
+ ;; mounted NFS directories or SMB/AFP shares; such more granular
+ ;; tests will be added in case they are needed.
+ (setq filename (expand-file-name filename))
+ (with-parsed-tramp-file-name filename nil
+ (or ;; Maybe there is a default value.
+ (tramp-get-method-parameter v 'tramp-case-insensitive)
+
+ ;; There isn't. So we must check, in case there's a connection already.
+ (and (tramp-connectable-p filename)
+ (with-tramp-connection-property v "case-insensitive"
+ ;; The idea is to compare a file with lower case letters
+ ;; with the same file with upper case letters.
+ (let ((candidate
+ (tramp-compat-file-name-unquote
+ (directory-file-name filename)))
+ tmpfile)
+ ;; Check, whether we find an existing file with lower case
+ ;; letters. This avoids us to create a temporary file.
+ (while (and (string-match
+ "[a-z]" (file-remote-p candidate 'localname))
+ (not (file-exists-p candidate)))
+ (setq candidate
+ (directory-file-name (file-name-directory candidate))))
+ ;; Nothing found, so we must use a temporary file for
+ ;; comparison. `make-nearby-temp-file' is added to
+ ;; Emacs 26+ like `file-name-case-insensitive-p', so
+ ;; there is no compatibility problem calling it.
+ (unless
+ (string-match "[a-z]" (file-remote-p candidate 'localname))
+ (setq tmpfile
+ (let ((default-directory (file-name-directory filename)))
+ (tramp-compat-funcall 'make-nearby-temp-file "tramp."))
+ candidate tmpfile))
+ ;; Check for the existence of the same file with upper
+ ;; case letters.
+ (unwind-protect
+ (file-exists-p
+ (concat
+ (file-remote-p candidate)
+ (upcase (file-remote-p candidate 'localname))))
+ ;; Cleanup.
+ (when tmpfile (delete-file tmpfile)))))))))
+
(defun tramp-handle-file-name-completion
(filename directory &optional predicate)
"Like `file-name-completion' for Tramp files."
@@ -2962,11 +2944,21 @@ User is always nil."
(error
"tramp-handle-file-name-completion invoked on non-tramp directory `%s'"
directory))
- (try-completion
- filename
- (mapcar 'list (file-name-all-completions filename directory))
- (when predicate
- (lambda (x) (funcall predicate (expand-file-name (car x) directory))))))
+ (let (hits-ignored-extensions)
+ (or
+ (try-completion
+ filename (file-name-all-completions filename directory)
+ (lambda (x)
+ (when (funcall (or predicate 'identity) (expand-file-name x directory))
+ (not
+ (and
+ completion-ignored-extensions
+ (string-match
+ (concat (regexp-opt completion-ignored-extensions 'paren) "$") x)
+ ;; We remember the hit.
+ (push x hits-ignored-extensions))))))
+ ;; No match. So we try again for ignored files.
+ (try-completion filename hits-ignored-extensions))))
(defun tramp-handle-file-name-directory (file)
"Like `file-name-directory' but aware of Tramp files."
@@ -2994,13 +2986,17 @@ User is always nil."
(cond
((not (file-exists-p file1)) nil)
((not (file-exists-p file2)) t)
- (t (time-less-p (nth 5 (file-attributes file2))
- (nth 5 (file-attributes file1))))))
+ (t (time-less-p (tramp-compat-file-attribute-modification-time
+ (file-attributes file2))
+ (tramp-compat-file-attribute-modification-time
+ (file-attributes file1))))))
(defun tramp-handle-file-regular-p (filename)
"Like `file-regular-p' for Tramp files."
(and (file-exists-p filename)
- (eq ?- (aref (nth 8 (file-attributes filename)) 0))))
+ (eq ?-
+ (aref (tramp-compat-file-attribute-modes (file-attributes filename))
+ 0))))
(defun tramp-handle-file-remote-p (filename &optional identification connected)
"Like `file-remote-p' for Tramp files."
@@ -3009,7 +3005,7 @@ User is always nil."
(when (tramp-tramp-file-p filename)
(let* ((v (tramp-dissect-file-name filename))
(p (tramp-get-connection-process v))
- (c (and p (processp p) (memq (process-status p) '(run open))
+ (c (and (tramp-compat-process-live-p p)
(tramp-get-connection-property p "connected" nil))))
;; We expand the file name only, if there is already a connection.
(with-parsed-tramp-file-name
@@ -3026,7 +3022,7 @@ User is always nil."
(defun tramp-handle-file-symlink-p (filename)
"Like `file-symlink-p' for Tramp files."
(with-parsed-tramp-file-name filename nil
- (let ((x (car (file-attributes filename))))
+ (let ((x (tramp-compat-file-attribute-type (file-attributes filename))))
(when (stringp x)
(if (file-name-absolute-p x)
(tramp-make-tramp-file-name method user host x)
@@ -3035,43 +3031,19 @@ User is always nil."
(defun tramp-handle-find-backup-file-name (filename)
"Like `find-backup-file-name' for Tramp files."
(with-parsed-tramp-file-name filename nil
- ;; We set both variables. It doesn't matter whether it is
- ;; Emacs or XEmacs.
(let ((backup-directory-alist
- ;; Emacs case.
- (when (boundp 'backup-directory-alist)
- (if (symbol-value 'tramp-backup-directory-alist)
- (mapcar
- (lambda (x)
- (cons
- (car x)
- (if (and (stringp (cdr x))
- (file-name-absolute-p (cdr x))
- (not (tramp-file-name-p (cdr x))))
- (tramp-make-tramp-file-name method user host (cdr x))
- (cdr x))))
- (symbol-value 'tramp-backup-directory-alist))
- (symbol-value 'backup-directory-alist))))
-
- (bkup-backup-directory-info
- ;; XEmacs case.
- (when (boundp 'bkup-backup-directory-info)
- (if (symbol-value 'tramp-bkup-backup-directory-info)
- (mapcar
- (lambda (x)
- (nconc
- (list (car x))
- (list
- (if (and (stringp (car (cdr x)))
- (file-name-absolute-p (car (cdr x)))
- (not (tramp-file-name-p (car (cdr x)))))
- (tramp-make-tramp-file-name
- method user host (car (cdr x)))
- (car (cdr x))))
- (cdr (cdr x))))
- (symbol-value 'tramp-bkup-backup-directory-info))
- (symbol-value 'bkup-backup-directory-info)))))
-
+ (if tramp-backup-directory-alist
+ (mapcar
+ (lambda (x)
+ (cons
+ (car x)
+ (if (and (stringp (cdr x))
+ (file-name-absolute-p (cdr x))
+ (not (tramp-file-name-p (cdr x))))
+ (tramp-make-tramp-file-name method user host (cdr x))
+ (cdr x))))
+ tramp-backup-directory-alist)
+ backup-directory-alist)))
(tramp-run-real-handler 'find-backup-file-name (list filename)))))
(defun tramp-handle-insert-directory
@@ -3116,7 +3088,8 @@ User is always nil."
(unwind-protect
(if (not (file-exists-p filename))
(tramp-error
- v 'file-error "File `%s' not found on remote host" filename)
+ v tramp-file-missing
+ "File `%s' not found on remote host" filename)
(with-tramp-progress-reporter
v 3 (format-message "Inserting `%s'" filename)
@@ -3182,8 +3155,7 @@ User is always nil."
;; When the file is not readable for the owner, it
;; cannot be inserted, even if it is readable for the
;; group or for everybody.
- (set-file-modes
- local-copy (tramp-compat-octal-to-decimal "0600"))
+ (set-file-modes local-copy (string-to-number "0600" 8))
(when (and (null remote-copy)
(tramp-get-method-parameter
@@ -3193,9 +3165,7 @@ User is always nil."
(setq tramp-temp-buffer-file-name local-copy))
;; We must ensure that `file-coding-system-alist'
- ;; matches `local-copy'. We must also use `visit',
- ;; otherwise there might be an error in the
- ;; `revert-buffer' function under XEmacs.
+ ;; matches `local-copy'.
(let ((file-coding-system-alist
(tramp-find-file-name-coding-system-alist
filename local-copy)))
@@ -3244,14 +3214,15 @@ User is always nil."
"File `%s' does not include a `.el' or `.elc' suffix" file)))
(unless noerror
(when (not (file-exists-p file))
- (tramp-error v 'file-error "Cannot load nonexistent file `%s'" file)))
+ (tramp-error
+ v tramp-file-missing "Cannot load nonexistent file `%s'" file)))
(if (not (file-exists-p file))
nil
(let ((tramp-message-show-message (not nomessage)))
(with-tramp-progress-reporter v 0 (format "Loading %s" file)
(let ((local-copy (file-local-copy file)))
(unwind-protect
- (tramp-compat-load local-copy noerror t nosuffix must-suffix)
+ (load local-copy noerror t nosuffix must-suffix)
(delete-file local-copy)))))
t)))
@@ -3305,7 +3276,7 @@ User is always nil."
(when p
(if (yes-or-no-p "A command is running. Kill it? ")
(ignore-errors (kill-process p))
- (tramp-user-error p "Shell command in progress")))
+ (tramp-compat-user-error p "Shell command in progress")))
(if current-buffer-p
(progn
@@ -3345,35 +3316,28 @@ User is always nil."
(current-buffer))))
;; There's some output, display it.
(when (with-current-buffer output-buffer (> (point-max) (point-min)))
- (if (functionp 'display-message-or-buffer)
- (tramp-compat-funcall 'display-message-or-buffer output-buffer)
- (pop-to-buffer output-buffer))))))))
+ (display-message-or-buffer output-buffer)))))))
(defun tramp-handle-substitute-in-file-name (filename)
"Like `substitute-in-file-name' for Tramp files.
\"//\" and \"/~\" substitute only in the local filename part."
- ;; First, we must replace environment variables.
- (setq filename (tramp-replace-environment-variables filename))
- (with-parsed-tramp-file-name filename nil
- ;; Ignore in LOCALNAME everything before "//" or "/~".
- (when (and (stringp localname) (string-match ".+?/\\(/\\|~\\)" localname))
- (setq filename
- (concat (file-remote-p filename)
- (replace-match "\\1" nil nil localname)))
- ;; "/m:h:~" does not work for completion. We use "/m:h:~/".
- (when (string-match "~$" filename)
- (setq filename (concat filename "/"))))
- ;; We do not want to replace environment variables, again.
- (let (process-environment)
- (tramp-run-real-handler 'substitute-in-file-name (list filename)))))
-
-(defun tramp-handle-unhandled-file-name-directory (_filename)
- "Like `unhandled-file-name-directory' for Tramp files."
- ;; Starting with Emacs 23, we must simply return nil. But we must
- ;; keep backward compatibility, also with XEmacs. "~/" cannot be
- ;; returned, because there might be machines without a HOME
- ;; directory (like hydra).
- (and (< emacs-major-version 23) "/"))
+ ;; Check, whether the local part is a quoted file name.
+ (if (tramp-compat-file-name-quoted-p filename)
+ filename
+ ;; First, we must replace environment variables.
+ (setq filename (tramp-replace-environment-variables filename))
+ (with-parsed-tramp-file-name filename nil
+ ;; Ignore in LOCALNAME everything before "//" or "/~".
+ (when (and (stringp localname) (string-match ".+?/\\(/\\|~\\)" localname))
+ (setq filename
+ (concat (file-remote-p filename)
+ (replace-match "\\1" nil nil localname)))
+ ;; "/m:h:~" does not work for completion. We use "/m:h:~/".
+ (when (string-match "~$" filename)
+ (setq filename (concat filename "/"))))
+ ;; We do not want to replace environment variables, again.
+ (let (process-environment)
+ (tramp-run-real-handler 'substitute-in-file-name (list filename))))))
(defun tramp-handle-set-visited-file-modtime (&optional time-list)
"Like `set-visited-file-modtime' for Tramp files."
@@ -3384,7 +3348,9 @@ User is always nil."
(let ((remote-file-name-inhibit-cache t))
;; '(-1 65535) means file doesn't exists yet.
(setq time-list
- (or (nth 5 (file-attributes (buffer-file-name))) '(-1 65535)))))
+ (or (tramp-compat-file-attribute-modification-time
+ (file-attributes (buffer-file-name)))
+ '(-1 65535)))))
;; We use '(0 0) as a don't-know value.
(unless (equal time-list '(0 0))
(tramp-run-real-handler 'set-visited-file-modtime (list time-list))))
@@ -3403,12 +3369,12 @@ of."
;; connection.
(if (or (not f)
(eq (visited-file-modtime) 0)
- (not (tramp-file-name-handler 'file-remote-p f nil 'connected)))
+ (not (file-remote-p f nil 'connected)))
t
(with-parsed-tramp-file-name f nil
(let* ((remote-file-name-inhibit-cache t)
(attr (file-attributes f))
- (modtime (nth 5 attr))
+ (modtime (tramp-compat-file-attribute-modification-time attr))
(mt (visited-file-modtime)))
(cond
@@ -3448,13 +3414,13 @@ of."
(defun tramp-handle-file-notify-valid-p (proc)
"Like `file-notify-valid-p' for Tramp files."
- (and proc (processp proc) (memq (process-status proc) '(run open))
+ (and (tramp-compat-process-live-p proc)
;; Sometimes, the process is still in status `run' when the
;; file or directory to be watched is deleted already.
(with-current-buffer (process-buffer proc)
(file-exists-p
(concat (file-remote-p default-directory)
- (tramp-compat-process-get proc 'watch-name))))))
+ (process-get proc 'watch-name))))))
;;; Functions for establishing connection:
@@ -3543,14 +3509,14 @@ The terminal type can be configured with `tramp-terminal-type'."
(defun tramp-action-process-alive (proc _vec)
"Check, whether a process has finished."
- (unless (memq (process-status proc) '(run open))
+ (unless (tramp-compat-process-live-p proc)
(throw 'tramp-action 'process-died)))
(defun tramp-action-out-of-band (proc vec)
"Check, whether an out-of-band copy has finished."
;; There might be pending output for the exit status.
(tramp-accept-process-output proc 0.1)
- (cond ((and (memq (process-status proc) '(stop exit))
+ (cond ((and (not (tramp-compat-process-live-p proc))
(zerop (process-exit-status proc)))
(tramp-message vec 3 "Process has finished.")
(throw 'tramp-action 'ok))
@@ -3567,7 +3533,7 @@ The terminal type can be configured with `tramp-terminal-type'."
(tramp-message vec 3 "Process has finished.")
(throw 'tramp-action 'ok))
(tramp-message vec 3 "Process has died.")
- (throw 'tramp-action 'process-died))))
+ (throw 'tramp-action 'out-of-band-failed))))
(t nil)))
;;; Functions for processing the actions:
@@ -3628,6 +3594,10 @@ connection buffer."
(tramp-get-connection-buffer vec) vec 'file-error
(cond
((eq exit 'permission-denied) "Permission denied")
+ ((eq exit 'out-of-band-failed)
+ (format-message
+ "Copy failed, see buffer `%s' for details"
+ (tramp-get-connection-buffer vec)))
((eq exit 'process-died)
(substitute-command-keys
(concat
@@ -3649,19 +3619,13 @@ connection buffer."
This is needed in order to hide `last-coding-system-used', which is set
for process communication also."
(with-current-buffer (process-buffer proc)
- ;; FIXME: If there is a gateway process, we need communication
- ;; between several processes. Too complicate to implement, so we
- ;; read output from all processes.
- (let ((p (if (tramp-get-connection-property proc "gateway" nil) nil proc))
- buffer-read-only last-coding-system-used)
+ (let (buffer-read-only last-coding-system-used)
;; Under Windows XP, accept-process-output doesn't return
;; sometimes. So we add an additional timeout.
(with-timeout ((or timeout 1))
- (if (featurep 'xemacs)
- (accept-process-output p timeout timeout-msecs)
- (accept-process-output p timeout timeout-msecs (and proc t))))
- (tramp-message proc 10 "%s %s %s\n%s"
- proc (process-status proc) p (buffer-string)))))
+ (accept-process-output proc timeout timeout-msecs (and proc t)))
+ (tramp-message proc 10 "%s %s\n%s"
+ proc (process-status proc) (buffer-string)))))
(defun tramp-check-for-regexp (proc regexp)
"Check, whether REGEXP is contained in process buffer of PROC.
@@ -3684,11 +3648,10 @@ Erase echoed commands if exists."
(when (or (not (tramp-get-connection-property proc "check-remote-echo" nil))
;; Sometimes, the echo string is suppressed on the remote side.
(not (string-equal
- (tramp-compat-funcall
- 'substring-no-properties tramp-echo-mark-marker
+ (substring-no-properties
+ tramp-echo-mark-marker
0 (min tramp-echo-mark-marker-length (1- (point-max))))
- (tramp-compat-funcall
- 'buffer-substring-no-properties
+ (buffer-substring-no-properties
(point-min)
(min (+ (point-min) tramp-echo-mark-marker-length)
(point-max))))))
@@ -3706,26 +3669,19 @@ Expects the output of PROC to be sent to the current buffer. Returns
the string that matched, or nil. Waits indefinitely if TIMEOUT is
nil."
(with-current-buffer (process-buffer proc)
- (let ((found (tramp-check-for-regexp proc regexp))
- (start-time (current-time)))
+ (let ((found (tramp-check-for-regexp proc regexp)))
(cond (timeout
- ;; Work around a bug in XEmacs 21, where the timeout
- ;; expires faster than it should. This degenerates
- ;; to polling for buggy XEmacsen, but oh, well.
- (while (and (not found)
- (< (tramp-time-diff (current-time) start-time)
- timeout))
- (with-timeout (timeout)
- (while (not found)
- (tramp-accept-process-output proc 1)
- (unless (memq (process-status proc) '(run open))
- (tramp-error-with-buffer
- nil proc 'file-error "Process has died"))
- (setq found (tramp-check-for-regexp proc regexp))))))
+ (with-timeout (timeout)
+ (while (not found)
+ (tramp-accept-process-output proc 1)
+ (unless (tramp-compat-process-live-p proc)
+ (tramp-error-with-buffer
+ nil proc 'file-error "Process has died"))
+ (setq found (tramp-check-for-regexp proc regexp)))))
(t
(while (not found)
(tramp-accept-process-output proc 1)
- (unless (memq (process-status proc) '(run open))
+ (unless (tramp-compat-process-live-p proc)
(tramp-error-with-buffer
nil proc 'file-error "Process has died"))
(setq found (tramp-check-for-regexp proc regexp)))))
@@ -3761,9 +3717,8 @@ the remote host use line-endings as defined in the variable
(let (buffer-read-only) (delete-region (point-min) (point-max)))
;; Replace "\n" by `tramp-rsh-end-of-line'.
(setq string
- (mapconcat 'identity
- (tramp-compat-split-string string "\n")
- tramp-rsh-end-of-line))
+ (mapconcat
+ 'identity (split-string string "\n") tramp-rsh-end-of-line))
(unless (or (string= string "")
(string-equal (substring string -1) tramp-rsh-end-of-line))
(setq string (concat string tramp-rsh-end-of-line)))
@@ -3827,57 +3782,47 @@ would yield t. On the other hand, the following check results in nil:
(save-match-data
(logior
(cond
- ((char-equal owner-read ?r) (tramp-compat-octal-to-decimal "00400"))
+ ((char-equal owner-read ?r) (string-to-number "00400" 8))
((char-equal owner-read ?-) 0)
(t (error "Second char `%c' must be one of `r-'" owner-read)))
(cond
- ((char-equal owner-write ?w) (tramp-compat-octal-to-decimal "00200"))
+ ((char-equal owner-write ?w) (string-to-number "00200" 8))
((char-equal owner-write ?-) 0)
(t (error "Third char `%c' must be one of `w-'" owner-write)))
(cond
- ((char-equal owner-execute-or-setid ?x)
- (tramp-compat-octal-to-decimal "00100"))
- ((char-equal owner-execute-or-setid ?S)
- (tramp-compat-octal-to-decimal "04000"))
- ((char-equal owner-execute-or-setid ?s)
- (tramp-compat-octal-to-decimal "04100"))
+ ((char-equal owner-execute-or-setid ?x) (string-to-number "00100" 8))
+ ((char-equal owner-execute-or-setid ?S) (string-to-number "04000" 8))
+ ((char-equal owner-execute-or-setid ?s) (string-to-number "04100" 8))
((char-equal owner-execute-or-setid ?-) 0)
(t (error "Fourth char `%c' must be one of `xsS-'"
owner-execute-or-setid)))
(cond
- ((char-equal group-read ?r) (tramp-compat-octal-to-decimal "00040"))
+ ((char-equal group-read ?r) (string-to-number "00040" 8))
((char-equal group-read ?-) 0)
(t (error "Fifth char `%c' must be one of `r-'" group-read)))
(cond
- ((char-equal group-write ?w) (tramp-compat-octal-to-decimal "00020"))
+ ((char-equal group-write ?w) (string-to-number "00020" 8))
((char-equal group-write ?-) 0)
(t (error "Sixth char `%c' must be one of `w-'" group-write)))
(cond
- ((char-equal group-execute-or-setid ?x)
- (tramp-compat-octal-to-decimal "00010"))
- ((char-equal group-execute-or-setid ?S)
- (tramp-compat-octal-to-decimal "02000"))
- ((char-equal group-execute-or-setid ?s)
- (tramp-compat-octal-to-decimal "02010"))
+ ((char-equal group-execute-or-setid ?x) (string-to-number "00010" 8))
+ ((char-equal group-execute-or-setid ?S) (string-to-number "02000" 8))
+ ((char-equal group-execute-or-setid ?s) (string-to-number "02010" 8))
((char-equal group-execute-or-setid ?-) 0)
(t (error "Seventh char `%c' must be one of `xsS-'"
group-execute-or-setid)))
(cond
- ((char-equal other-read ?r)
- (tramp-compat-octal-to-decimal "00004"))
+ ((char-equal other-read ?r) (string-to-number "00004" 8))
((char-equal other-read ?-) 0)
(t (error "Eighth char `%c' must be one of `r-'" other-read)))
(cond
- ((char-equal other-write ?w) (tramp-compat-octal-to-decimal "00002"))
- ((char-equal other-write ?-) 0)
- (t (error "Ninth char `%c' must be one of `w-'" other-write)))
+ ((char-equal other-write ?w) (string-to-number "00002" 8))
+ ((char-equal other-write ?-) 0)
+ (t (error "Ninth char `%c' must be one of `w-'" other-write)))
(cond
- ((char-equal other-execute-or-sticky ?x)
- (tramp-compat-octal-to-decimal "00001"))
- ((char-equal other-execute-or-sticky ?T)
- (tramp-compat-octal-to-decimal "01000"))
- ((char-equal other-execute-or-sticky ?t)
- (tramp-compat-octal-to-decimal "01001"))
+ ((char-equal other-execute-or-sticky ?x) (string-to-number "00001" 8))
+ ((char-equal other-execute-or-sticky ?T) (string-to-number "01000" 8))
+ ((char-equal other-execute-or-sticky ?t) (string-to-number "01001" 8))
((char-equal other-execute-or-sticky ?-) 0)
(t (error "Tenth char `%c' must be one of `xtT-'"
other-execute-or-sticky)))))))
@@ -3931,15 +3876,22 @@ This is used internally by `tramp-file-mode-from-int'."
;;;###tramp-autoload
(defun tramp-get-local-uid (id-format)
+ "The uid of the local user, in ID-FORMAT.
+ID-FORMAT valid values are `string' and `integer'."
(if (equal id-format 'integer) (user-uid) (user-login-name)))
;;;###tramp-autoload
(defun tramp-get-local-gid (id-format)
+ "The gid of the local user, in ID-FORMAT.
+ID-FORMAT valid values are `string' and `integer'."
+ ;; `group-gid' has been introduced with Emacs 24.4.
(if (and (fboundp 'group-gid) (equal id-format 'integer))
(tramp-compat-funcall 'group-gid)
- (nth 3 (tramp-compat-file-attributes "~/" id-format))))
+ (tramp-compat-file-attribute-group-id (file-attributes "~/" id-format))))
(defun tramp-get-local-locale (&optional vec)
+ "Determine locale, supporting UTF8 if possible.
+VEC is used for tracing."
;; We use key nil for local connection properties.
(with-tramp-connection-property nil "locale"
(let ((candidates '("en_US.utf8" "C.utf8" "en_US.UTF-8"))
@@ -3979,7 +3931,7 @@ be granted."
(tramp-get-file-property
vec (tramp-file-name-localname vec)
(concat "file-attributes-" suffix) nil)
- (tramp-compat-file-attributes
+ (file-attributes
(tramp-make-tramp-file-name
(tramp-file-name-method vec)
(tramp-file-name-user vec)
@@ -3992,25 +3944,39 @@ be granted."
vec (concat "uid-" suffix) nil))
(remote-gid
(tramp-get-connection-property
- vec (concat "gid-" suffix) nil)))
+ vec (concat "gid-" suffix) nil))
+ (unknown-id
+ (if (string-equal suffix "string")
+ tramp-unknown-id-string tramp-unknown-id-integer)))
(and
file-attr
(or
- ;; Not a symlink
- (eq t (car file-attr))
- (null (car file-attr)))
+ ;; Not a symlink.
+ (eq t (tramp-compat-file-attribute-type file-attr))
+ (null (tramp-compat-file-attribute-type file-attr)))
(or
;; World accessible.
- (eq access (aref (nth 8 file-attr) (+ offset 6)))
+ (eq access
+ (aref (tramp-compat-file-attribute-modes file-attr)
+ (+ offset 6)))
;; User accessible and owned by user.
(and
- (eq access (aref (nth 8 file-attr) offset))
- (equal remote-uid (nth 2 file-attr)))
- ;; Group accessible and owned by user's
- ;; principal group.
+ (eq access
+ (aref (tramp-compat-file-attribute-modes file-attr) offset))
+ (or (equal remote-uid
+ (tramp-compat-file-attribute-user-id file-attr))
+ (equal unknown-id
+ (tramp-compat-file-attribute-user-id file-attr))))
+ ;; Group accessible and owned by user's principal group.
(and
- (eq access (aref (nth 8 file-attr) (+ offset 3)))
- (equal remote-gid (nth 3 file-attr)))))))))))
+ (eq access
+ (aref (tramp-compat-file-attribute-modes file-attr)
+ (+ offset 3)))
+ (or (equal remote-gid
+ (tramp-compat-file-attribute-group-id file-attr))
+ (equal unknown-id
+ (tramp-compat-file-attribute-group-id
+ file-attr))))))))))))
;;;###tramp-autoload
(defun tramp-local-host-p (vec)
@@ -4040,19 +4006,17 @@ be granted."
(defun tramp-get-remote-tmpdir (vec)
"Return directory for temporary files on the remote host identified by VEC."
- (when (file-remote-p (tramp-get-connection-property vec "tmpdir" ""))
- ;; Compatibility code: Cached value shall be the local path only.
- (tramp-set-connection-property vec "tmpdir" 'undef))
- (let ((dir (tramp-make-tramp-file-name
- (tramp-file-name-method vec)
- (tramp-file-name-user vec)
- (tramp-file-name-host vec)
- (or (tramp-get-method-parameter vec 'tramp-tmpdir) "/tmp"))))
- (with-tramp-connection-property vec "tmpdir"
+ (with-tramp-connection-property vec "tmpdir"
+ (let ((dir (tramp-make-tramp-file-name
+ (tramp-file-name-method vec)
+ (tramp-file-name-user vec)
+ (tramp-file-name-host vec)
+ (or (tramp-get-method-parameter vec 'tramp-tmpdir) "/tmp")
+ (tramp-file-name-hop vec))))
(or (and (file-directory-p dir) (file-writable-p dir)
- (tramp-file-name-handler 'file-remote-p dir 'localname))
- (tramp-error vec 'file-error "Directory %s not accessible" dir)))
- dir))
+ (file-remote-p dir 'localname))
+ (tramp-error vec 'file-error "Directory %s not accessible" dir))
+ dir)))
;;;###tramp-autoload
(defun tramp-make-tramp-temp-file (vec)
@@ -4071,7 +4035,7 @@ Return the local name of the temporary file."
(setq result nil)
;; This creates the file by side effect.
(set-file-times result)
- (set-file-modes result (tramp-compat-octal-to-decimal "0700"))))
+ (set-file-modes result (string-to-number "0700" 8))))
;; Return the local part.
(with-parsed-tramp-file-name result nil localname)))
@@ -4087,9 +4051,6 @@ Return the local name of the temporary file."
(remove-hook 'kill-buffer-hook
'tramp-delete-temp-file-function)))
-;;; Auto saving to a special directory:
-(defvar auto-save-file-name-transforms)
-
(defun tramp-handle-make-auto-save-file-name ()
"Like `make-auto-save-file-name' for Tramp files.
Returns a file name in `tramp-auto-save-directory' for autosaving
@@ -4104,9 +4065,8 @@ this file, if that variable is non-nil."
(let ((system-type 'not-windows)
(auto-save-file-name-transforms
- (if (and (null tramp-auto-save-directory)
- (boundp 'auto-save-file-name-transforms))
- (symbol-value 'auto-save-file-name-transforms)))
+ (if (null tramp-auto-save-directory)
+ auto-save-file-name-transforms))
(buffer-file-name
(if (null tramp-auto-save-directory)
buffer-file-name
@@ -4118,63 +4078,10 @@ this file, if that variable is non-nil."
("|" . "__")
("[" . "_l")
("]" . "_r"))
- (buffer-file-name))
+ (tramp-compat-file-name-unquote (buffer-file-name)))
tramp-auto-save-directory))))
- ;; Run plain `make-auto-save-file-name'. There might be an advice when
- ;; it is not a magic file name operation (since Emacs 22).
- ;; We must deactivate it temporarily.
- (if (not (ad-is-active 'make-auto-save-file-name))
- (tramp-run-real-handler 'make-auto-save-file-name nil)
- ;; else
- (ad-deactivate 'make-auto-save-file-name)
- (prog1
- (tramp-run-real-handler 'make-auto-save-file-name nil)
- (ad-activate 'make-auto-save-file-name)))))
-
-(unless (tramp-exists-file-name-handler 'make-auto-save-file-name)
- (defadvice make-auto-save-file-name
- (around tramp-advice-make-auto-save-file-name () activate)
- "Invoke `tramp-*-handle-make-auto-save-file-name' for Tramp files."
- (if (tramp-tramp-file-p (buffer-file-name))
- ;; We cannot call `tramp-handle-make-auto-save-file-name'
- ;; directly, because this would bypass the locking mechanism.
- (setq ad-return-value
- (tramp-file-name-handler 'make-auto-save-file-name))
- ad-do-it))
- (add-hook
- 'tramp-unload-hook
- (lambda ()
- (ad-remove-advice
- 'make-auto-save-file-name
- 'around 'tramp-advice-make-auto-save-file-name)
- (ad-activate 'make-auto-save-file-name))))
-
-;; In XEmacs < 21.5, autosaved remote files have permission 0666 minus
-;; umask. This is a security threat.
-
-(defun tramp-set-auto-save-file-modes ()
- "Set permissions of autosaved remote files to the original permissions."
- (let ((bfn (buffer-file-name)))
- (when (and (tramp-tramp-file-p bfn)
- (buffer-modified-p)
- (stringp buffer-auto-save-file-name)
- (not (equal bfn buffer-auto-save-file-name)))
- (unless (file-exists-p buffer-auto-save-file-name)
- (write-region "" nil buffer-auto-save-file-name))
- ;; Permissions should be set always, because there might be an old
- ;; auto-saved file belonging to another original file. This could
- ;; be a security threat.
- (set-file-modes
- buffer-auto-save-file-name
- (or (file-modes bfn) (tramp-compat-octal-to-decimal "0600"))))))
-
-(unless (and (featurep 'xemacs)
- (= emacs-major-version 21)
- (> emacs-minor-version 4))
- (add-hook 'auto-save-hook 'tramp-set-auto-save-file-modes)
- (add-hook 'tramp-unload-hook
- (lambda ()
- (remove-hook 'auto-save-hook 'tramp-set-auto-save-file-modes))))
+ ;; Run plain `make-auto-save-file-name'.
+ (tramp-run-real-handler 'make-auto-save-file-name nil)))
(defun tramp-subst-strs-in-string (alist string)
"Replace all occurrences of the string FROM with TO in STRING.
@@ -4189,6 +4096,22 @@ ALIST is of the form ((FROM . TO) ...)."
(setq alist (cdr alist))))
string))
+(defun tramp-handle-temporary-file-directory ()
+ "Like `temporary-file-directory' for Tramp files."
+ (catch 'result
+ (dolist (dir `(,(ignore-errors
+ (tramp-get-remote-tmpdir
+ (tramp-dissect-file-name default-directory)))
+ ,default-directory))
+ (when (and (stringp dir) (file-directory-p dir) (file-writable-p dir))
+ (throw 'result (expand-file-name dir))))))
+
+(defun tramp-handle-make-nearby-temp-file (prefix &optional dir-flag suffix)
+ "Like `make-nearby-temp-file' for Tramp files."
+ (let ((temporary-file-directory
+ (tramp-compat-temporary-file-directory-function)))
+ (make-temp-file prefix dir-flag suffix)))
+
;;; Compatibility functions section:
(defun tramp-call-process
@@ -4197,11 +4120,12 @@ ALIST is of the form ((FROM . TO) ...)."
It always returns a return code. The Lisp error raised when
PROGRAM is nil is trapped also, returning 1. Furthermore, traces
are written with verbosity of 6."
- (let ((v (or vec
+ (let ((default-directory (tramp-compat-temporary-file-directory))
+ (v (or vec
(vector tramp-current-method tramp-current-user
tramp-current-host nil nil)))
(destination (if (eq destination t) (current-buffer) destination))
- result)
+ output error result)
(tramp-message
v 6 "`%s %s' %s %s"
program (mapconcat 'identity args " ") infile destination)
@@ -4212,13 +4136,17 @@ are written with verbosity of 6."
'call-process program infile (or destination t) display args))
;; `result' could also be an error string.
(when (stringp result)
- (signal 'file-error (list result)))
+ (setq error result
+ result 1))
(with-current-buffer
(if (bufferp destination) destination (current-buffer))
- (tramp-message v 6 "%d\n%s" result (buffer-string))))
+ (setq output (buffer-string))))
(error
- (setq result 1)
- (tramp-message v 6 "%d\n%s" result (error-message-string err))))
+ (setq error (error-message-string err)
+ result 1)))
+ (if (zerop (length error))
+ (tramp-message v 6 "%d\n%s" result output)
+ (tramp-message v 6 "%d\n%s\n%s" result output error))
result))
(defun tramp-call-process-region
@@ -4227,7 +4155,8 @@ are written with verbosity of 6."
It always returns a return code. The Lisp error raised when
PROGRAM is nil is trapped also, returning 1. Furthermore, traces
are written with verbosity of 6."
- (let ((v (or vec
+ (let ((default-directory (tramp-compat-temporary-file-directory))
+ (v (or vec
(vector tramp-current-method tramp-current-user
tramp-current-host nil nil)))
(buffer (if (eq buffer t) (current-buffer) buffer))
@@ -4268,31 +4197,32 @@ Invokes `password-read' if available, `read-passwd' else."
(tramp-check-for-regexp proc tramp-password-prompt-regexp)
(format "%s for %s " (capitalize (match-string 1)) key))))
;; We suspend the timers while reading the password.
- (stimers (and (functionp 'with-timeout-suspend)
- (tramp-compat-funcall 'with-timeout-suspend)))
+ (stimers (with-timeout-suspend))
auth-info auth-passwd)
(unwind-protect
(with-parsed-tramp-file-name key nil
(prog1
(or
- ;; See if auth-sources contains something useful, if
- ;; it's bound. `auth-source-user-or-password' is an
- ;; obsoleted function, it has been replaced by
+ ;; See if auth-sources contains something useful.
+ ;; `auth-source-user-or-password' is an obsoleted
+ ;; function since Emacs 24.1, it has been replaced by
;; `auth-source-search'.
(ignore-errors
- (and (boundp 'auth-sources)
- (tramp-get-connection-property
+ (and (tramp-get-connection-property
v "first-password-request" nil)
;; Try with Tramp's current method.
(if (fboundp 'auth-source-search)
(setq auth-info
- (tramp-compat-funcall
- 'auth-source-search
+ (auth-source-search
:max 1
- :user (or tramp-current-user t)
+ (and tramp-current-user :user)
+ tramp-current-user
:host tramp-current-host
- :port tramp-current-method)
+ :port tramp-current-method
+ :require
+ (cons
+ :secret (and tramp-current-user '(:user))))
auth-passwd (plist-get
(nth 0 auth-info) :secret)
auth-passwd (if (functionp auth-passwd)
@@ -4302,73 +4232,55 @@ Invokes `password-read' if available, `read-passwd' else."
'auth-source-user-or-password
"password" tramp-current-host tramp-current-method))))
;; Try the password cache.
- (when (functionp 'password-read)
- (let ((password
- (tramp-compat-funcall 'password-read pw-prompt key)))
- (tramp-compat-funcall 'password-cache-add key password)
- password))
+ (let ((password (password-read pw-prompt key)))
+ (password-cache-add key password)
+ password)
;; Else, get the password interactively.
(read-passwd pw-prompt))
(tramp-set-connection-property v "first-password-request" nil)))
;; Reenable the timers.
- (and (functionp 'with-timeout-unsuspend)
- (tramp-compat-funcall 'with-timeout-unsuspend stimers)))))
+ (with-timeout-unsuspend stimers))))
;;;###tramp-autoload
(defun tramp-clear-passwd (vec)
"Clear password cache for connection related to VEC."
- (let ((hop (tramp-file-name-hop vec)))
+ (let ((method (tramp-file-name-method vec))
+ (user (tramp-file-name-user vec))
+ (host (tramp-file-name-host vec))
+ (hop (tramp-file-name-hop vec)))
(when hop
;; Clear also the passwords of the hops.
(tramp-clear-passwd
(tramp-dissect-file-name
(concat
tramp-prefix-format
- (tramp-compat-replace-regexp-in-string
+ (replace-regexp-in-string
(concat tramp-postfix-hop-regexp "$")
- tramp-postfix-host-format hop))))))
- (tramp-compat-funcall
- 'password-cache-remove
- (tramp-make-tramp-file-name
- (tramp-file-name-method vec)
- (tramp-file-name-user vec)
- (tramp-file-name-host vec)
- "")))
-
-;; Snarfed code from time-date.el and parse-time.el
+ tramp-postfix-host-format hop)))))
+ ;; `auth-source-forget-user-or-password' is an obsoleted function
+ ;; since Emacs 24.1, it has been replaced by `auth-source-forget'.
+ (if (fboundp 'auth-source-forget)
+ (auth-source-forget
+ `(:max 1 ,(and user :user) ,user :host ,host :port ,method))
+ (tramp-compat-funcall
+ 'auth-source-forget-user-or-password "password" host method))
+ (password-cache-remove (tramp-make-tramp-file-name method user host ""))))
+
+;; Snarfed code from time-date.el.
(defconst tramp-half-a-year '(241 17024)
"Evaluated by \"(days-to-time 183)\".")
-(defconst tramp-parse-time-months
- '(("jan" . 1) ("feb" . 2) ("mar" . 3)
- ("apr" . 4) ("may" . 5) ("jun" . 6)
- ("jul" . 7) ("aug" . 8) ("sep" . 9)
- ("oct" . 10) ("nov" . 11) ("dec" . 12))
- "Alist mapping month names to integers.")
-
;;;###tramp-autoload
(defun tramp-time-diff (t1 t2)
"Return the difference between the two times, in seconds.
T1 and T2 are time values (as returned by `current-time' for example)."
- (cond ((and (fboundp 'subtract-time)
- (fboundp 'float-time))
- (tramp-compat-funcall
- 'float-time (tramp-compat-funcall 'subtract-time t1 t2)))
- ((and (fboundp 'subtract-time)
- (fboundp 'time-to-seconds))
- (tramp-compat-funcall
- 'time-to-seconds (tramp-compat-funcall 'subtract-time t1 t2)))
- ((fboundp 'itimer-time-difference)
- (tramp-compat-funcall
- 'itimer-time-difference
- (if (< (length t1) 3) (append t1 '(0)) t1)
- (if (< (length t2) 3) (append t2 '(0)) t2)))
- (t
- (let ((time (time-subtract t1 t2)))
- (+ (* (car time) 65536.0)
- (cadr time)
- (/ (or (nth 2 time) 0) 1000000.0))))))
+ ;; Starting with Emacs 25.1, we could change this to use `time-subtract'.
+ (float-time (tramp-compat-funcall 'subtract-time t1 t2)))
+
+(defun tramp-unquote-shell-quote-argument (s)
+ "Remove quotation prefix \"/:\" from string S, and quote it then for shell."
+ (shell-quote-argument (tramp-compat-file-name-unquote s)))
;; Currently (as of Emacs 20.5), the function `shell-quote-argument'
;; does not deal well with newline characters. Newline is replaced by
@@ -4401,7 +4313,7 @@ T1 and T2 are time values (as returned by `current-time' for example)."
Only works for Bourne-like shells."
(let ((system-type 'not-windows))
(save-match-data
- (let ((result (shell-quote-argument s))
+ (let ((result (tramp-unquote-shell-quote-argument s))
(nl (regexp-quote (format "\\%s" tramp-rsh-end-of-line))))
(when (and (>= (length result) 2)
(string= (substring result 0 2) "\\~"))
@@ -4433,11 +4345,14 @@ Only works for Bourne-like shells."
(eval-after-load "esh-util"
'(progn
- (tramp-eshell-directory-change)
+ (add-hook 'eshell-mode-hook
+ 'tramp-eshell-directory-change)
(add-hook 'eshell-directory-change-hook
'tramp-eshell-directory-change)
(add-hook 'tramp-unload-hook
(lambda ()
+ (remove-hook 'eshell-mode-hook
+ 'tramp-eshell-directory-change)
(remove-hook 'eshell-directory-change-hook
'tramp-eshell-directory-change)))))
@@ -4462,31 +4377,33 @@ Only works for Bourne-like shells."
;; * In Emacs 21, `insert-directory' shows total number of bytes used
;; by the files in that directory. Add this here.
+;;
;; * Avoid screen blanking when hitting `g' in dired. (Eli Tziperman)
-;; * abbreviate-file-name
+;;
;; * Better error checking. At least whenever we see something
;; strange when doing zerop, we should kill the process and start
;; again. (Greg Stark)
-;; * Username and hostname completion.
-;; ** Try to avoid usage of `last-input-event' in `tramp-completion-mode-p'.
-;; * Make `tramp-default-user' obsolete.
-;; * Implement a general server-local-variable mechanism, as there are
-;; probably other variables that need different values for different
-;; servers too. The user could then configure a variable (such as
-;; tramp-server-local-variable-alist) to define any such variables
-;; that they need to, which would then be let bound as appropriate
-;; in tramp functions. (Jason Rumney)
+;;
;; * Make shadowfile.el grok Tramp filenames. (Bug#4526, Bug#4846)
+;;
;; * I was wondering if it would be possible to use tramp even if I'm
;; actually using sshfs. But when I launch a command I would like
;; to get it executed on the remote machine where the files really
;; are. (Andrea Crotti)
+;;
;; * Run emerge on two remote files. Bug is described here:
;; <http://www.mail-archive.com/tramp-devel@nongnu.org/msg01041.html>.
;; (Bug#6850)
+;;
;; * Use also port to distinguish connections. This is needed for
;; different hosts sitting behind a single router (distinguished by
;; different port numbers). (Tzvi Edelman)
+;;
+;; * Refactor code from different handlers. Start with
+;; *-process-file. One idea is to generalize `tramp-send-command'
+;; and friends, for most of the handlers this is the major
+;; difference between the different backends. Other handlers but
+;; *-process-file would profit from this as well.
;;; tramp.el ends here
diff --git a/lisp/net/trampver.el b/lisp/net/trampver.el
index 25e8b22d327..1cdbe161d52 100644
--- a/lisp/net/trampver.el
+++ b/lisp/net/trampver.el
@@ -6,7 +6,7 @@
;; Author: Kai Großjohann <kai.grossjohann@gmx.net>
;; Keywords: comm, processes
;; Package: tramp
-;; Version: 2.2.13.25.2
+;; Version: 2.3.1
;; This file is part of GNU Emacs.
@@ -27,45 +27,36 @@
;; In the Tramp GIT repository, the version number and the bug report
;; address are auto-frobbed from configure.ac, so you should edit that
-;; file and run "autoconf && ./configure" to change them. (X)Emacs
+;; file and run "autoconf && ./configure" to change them. Emacs
;; version check is defined in macro AC_EMACS_INFO of aclocal.m4;
;; should be changed only there.
;;;###tramp-autoload
-(defconst tramp-version "2.2.13.25.2"
+(defconst tramp-version "2.3.1"
"This version of Tramp.")
;;;###tramp-autoload
(defconst tramp-bug-report-address "tramp-devel@gnu.org"
"Email address to send bug reports to.")
-;; `locate-dominating-file' does not exist in XEmacs. But it is not used here.
-(autoload 'locate-dominating-file "files")
-(autoload 'tramp-compat-replace-regexp-in-string "tramp-compat")
-
(defun tramp-repository-get-version ()
"Try to return as a string the repository revision of the Tramp sources."
- (unless (featurep 'xemacs)
- (let ((dir (locate-dominating-file (locate-library "tramp") ".git")))
- (when dir
- (with-temp-buffer
- (let ((default-directory (file-name-as-directory dir)))
- (and (zerop
- (ignore-errors
- (call-process "git" nil '(t nil) nil "rev-parse" "HEAD")))
- (not (zerop (buffer-size)))
- (tramp-compat-replace-regexp-in-string
- "\n" "" (buffer-string)))))))))
-
-;; Check for (X)Emacs version.
-(let ((x (if (or (>= emacs-major-version 22)
- (and (featurep 'xemacs)
- (= emacs-major-version 21)
- (>= emacs-minor-version 4)))
- "ok"
- (format "Tramp 2.2.13.25.2 is not fit for %s"
- (when (string-match "^.*$" (emacs-version))
- (match-string 0 (emacs-version)))))))
+ (let ((dir (locate-dominating-file (locate-library "tramp") ".git")))
+ (when dir
+ (with-temp-buffer
+ (let ((default-directory (file-name-as-directory dir)))
+ (and (zerop
+ (ignore-errors
+ (call-process "git" nil '(t nil) nil "rev-parse" "HEAD")))
+ (not (zerop (buffer-size)))
+ (replace-regexp-in-string "\n" "" (buffer-string))))))))
+
+;; Check for Emacs version.
+(let ((x (if (>= emacs-major-version 23)
+ "ok"
+ (format "Tramp 2.3.1 is not fit for %s"
+ (when (string-match "^.*$" (emacs-version))
+ (match-string 0 (emacs-version)))))))
(unless (string-match "\\`ok\\'" x) (error "%s" x)))
(add-hook 'tramp-unload-hook
diff --git a/lisp/net/webjump.el b/lisp/net/webjump.el
index 41b7a7bb9cd..46f17afed47 100644
--- a/lisp/net/webjump.el
+++ b/lisp/net/webjump.el
@@ -67,142 +67,18 @@
;;------------------------------------------------------------------- Constants
-(defvar webjump-sample-sites
+(defgroup webjump nil
+ "Programmable Web hotlist."
+ :prefix "webjump-"
+ :group 'browse-url)
+
+(defconst webjump-sample-sites
'(
;; FSF, not including Emacs-specific.
("GNU Project FTP Archive" .
;; GNU FTP Mirror List from http://www.gnu.org/order/ftp.html
[mirrors "ftp://ftp.gnu.org/pub/gnu/"
- ;; United States
- "ftp://mirrors.kernel.org/gnu"
- "ftp://gatekeeper.dec.com/pub/GNU/"
- "ftp://ftp.keystealth.org/pub/gnu/"
- "ftp://mirrors.usc.edu/pub/gnu/"
- "ftp://cudlug.cudenver.edu/pub/mirrors/ftp.gnu.org/"
- "ftp://ftp.cise.ufl.edu/pub/mirrors/GNU/"
- "ftp://uiarchive.cso.uiuc.edu/pub/ftp/ftp.gnu.org/gnu/"
- "ftp://gnu.cs.lewisu.edu/gnu/"
- "ftp://ftp.in-span.net/pub/mirrors/ftp.gnu.org/"
- "ftp://gnu.ms.uky.edu/pub/mirrors/gnu/"
- "ftp://ftp.algx.net/pub/gnu/"
- "ftp://aeneas.mit.edu/pub/gnu/"
- "ftp://ftp.egr.msu.edu/pub/gnu/"
- "ftp://ftp.wayne.edu/pub/gnu/"
- "ftp://wuarchive.wustl.edu/mirrors/gnu/"
- "ftp://gnu.teleglobe.net/ftp.gnu.org/"
- "ftp://ftp.cs.columbia.edu/archives/gnu/prep/"
- "ftp://ftp.ece.cornell.edu/pub/mirrors/gnu/"
- "ftp://ftp.ibiblio.org/pub/mirrors/gnu/"
- "ftp://ftp.cis.ohio-state.edu/mirror/gnu/"
- "ftp://ftp.club.cc.cmu.edu/gnu/"
- "ftp://ftp.sunsite.utk.edu/pub/gnu/ftp/"
- "ftp://thales.memphis.edu/pub/gnu/"
- "ftp://gnu.wwc.edu"
- "ftp://ftp.twtelecom.net/pub/GNU/"
- ;; Africa
- "ftp://ftp.sun.ac.za/mirrorsites/ftp.gnu.org"
- ;; The Americas
- "ftp://ftp.unicamp.br/pub/gnu/"
- "ftp://master.softaplic.com.br/pub/gnu/"
- "ftp://ftp.matrix.com.br/pub/gnu/"
- "ftp://ftp.pucpr.br/gnu"
- "ftp://ftp.linorg.usp.br/gnu"
- "ftp://ftp.cs.ubc.ca/mirror2/gnu/"
- "ftp://cs.ubishops.ca/pub/ftp.gnu.org/"
- "ftp://ftp.inf.utfsm.cl/pub/gnu/"
- "ftp://sunsite.ulatina.ac.cr/Mirrors/GNU/"
- "ftp://www.gnu.unam.mx/pub/gnu/software/"
- "ftp://gnu.cem.itesm.mx/pub/mirrors/gnu.org/"
- "ftp://ftp.azc.uam.mx/mirrors/gnu/"
- ;; Australia
- "ftp://mirror.aarnet.edu.au/pub/gnu/"
- "ftp://gnu.mirror.pacific.net.au/gnu/"
- ;; Asia
- "ftp://ftp.cs.cuhk.edu.hk/pub/gnu/gnu/"
- "ftp://sunsite.ust.hk/pub/gnu/"
- "ftp://ftp.gnupilgrims.org/pub/gnu"
- "ftp://www.imtech.res.in/mirror/gnuftp/"
- "ftp://kambing.vlsm.org/gnu"
- "ftp://ftp.cs.huji.ac.il/mirror/GNU/"
- "ftp://tron.um.u-tokyo.ac.jp/pub/GNU/"
- "ftp://core.ring.gr.jp/pub/GNU/"
- "ftp://ftp.ring.gr.jp/pub/GNU/"
- "ftp://mirrors.hbi.co.jp/gnu/"
- "ftp://ftp.cs.titech.ac.jp/pub/gnu/"
- "ftp://ftpmirror.hanyang.ac.kr/GNU/"
- "ftp://ftp.linux.sarang.net/mirror/gnu/gnu/"
- "ftp://ftp.xgate.co.kr/pub/mirror/gnu/"
- "ftp://ftp://gnu.xinicks.com/"
- "ftp://ftp.isu.net.sa/pub/gnu/"
- "ftp://ftp.nctu.edu.tw/UNIX/gnu/"
- "ftp://coda.nctu.edu.tw/UNIX/gnu/"
- "ftp://ftp1.sinica.edu.tw/pub3/GNU/gnu/"
- "ftp://gnu.cdpa.nsysu.edu.tw/gnu"
- "ftp://ftp.nectec.or.th/pub/mirrors/gnu/"
- ;; Europe
- "ftp://ftp.gnu.vbs.at/"
- "ftp://ftp.univie.ac.at/packages/gnu/"
- "ftp://gd.tuwien.ac.at/gnu/gnusrc/"
- "ftp://ftp.belnet.be/mirror/ftp.gnu.org/"
- "ftp://gnu.blic.net/pub/gnu/"
- "ftp://ftp.fi.muni.cz/pub/gnu/"
- "ftp://ftp.dkuug.dk/pub/gnu/"
- "ftp://sunsite.dk/mirrors/gnu"
- "ftp://ftp.funet.fi/pub/gnu/prep/"
- "ftp://ftp.irisa.fr/pub/gnu/"
- "ftp://ftp.cs.univ-paris8.fr/mirrors/ftp.gnu.org/"
- "ftp://ftp.cs.tu-berlin.de/pub/gnu/"
- "ftp://ftp.leo.org/pub/comp/os/unix/gnu/"
- "ftp://ftp.informatik.rwth-aachen.de/pub/gnu/"
- "ftp://ftp.de.uu.net/pub/gnu/"
- "ftp://ftp.freenet.de/pub/ftp.gnu.org/gnu/"
- "ftp://ftp.cs.uni-bonn.de/pub/gnu/"
- "ftp://ftp-stud.fht-esslingen.de/pub/Mirrors/ftp.gnu.org/"
- "ftp://ftp.stw-bonn.de/pub/mirror/ftp.gnu.org/"
- "ftp://ftp.math.uni-bremen.de/pub/gnu"
- "ftp://ftp.forthnet.gr/pub/gnu/"
- "ftp://ftp.ntua.gr/pub/gnu/"
- "ftp://ftp.duth.gr/pub/gnu/"
- "ftp://ftp.physics.auth.gr/pub/gnu/"
- "ftp://ftp.esat.net/pub/gnu/"
- "ftp://ftp.heanet.ie/mirrors/ftp.gnu.org"
- "ftp://ftp.lugroma2.org/pub/gnu/"
- "ftp://ftp.gnu.inetcosmos.org/pub/gnu/"
- "ftp://ftp.digitaltrust.it/pub/gnu"
- "ftp://ftp://rm.mirror.garr.it/mirrors/gnuftp"
- "ftp://ftp.nluug.nl/pub/gnu/"
- "ftp://ftp.mirror.nl/pub/mirror/gnu/"
- "ftp://ftp.nl.uu.net/pub/gnu/"
- "ftp://mirror.widexs.nl/pub/gnu/"
- "ftp://ftp.easynet.nl/mirror/GNU/"
- "ftp://ftp.win.tue.nl/pub/gnu"
- "ftp://gnu.mirror.vuurwerk.net/pub/GNU/"
- "ftp://gnu.kookel.org/pub/ftp.gnu.org/"
- "ftp://ftp.uninett.no/pub/gnu/"
- "ftp://ftp.task.gda.pl/pub/gnu/"
- "ftp://sunsite.icm.edu.pl/pub/gnu/"
- "ftp://ftp.man.poznan.pl/pub/gnu"
- "ftp://ftp.ist.utl.pt/pub/GNU/gnu/"
- "ftp://ftp.telepac.pt/pub/gnu/"
- "ftp://ftp.timisoara.roedu.net/mirrors/ftp.gnu.org/pub/gnu"
- "ftp://ftp.chg.ru/pub/gnu/"
- "ftp://gnuftp.axitel.ru/"
- "ftp://ftp.arnes.si/software/gnu/"
- "ftp://ftp.etsimo.uniovi.es/pub/gnu/"
- "ftp://ftp.rediris.es/pub/gnu/"
- "ftp://ftp.chl.chalmers.se/pub/gnu/"
- "ftp://ftp.isy.liu.se/pub/gnu/"
- "ftp://ftp.luth.se/pub/unix/gnu/"
- "ftp://ftp.stacken.kth.se/pub/gnu/"
- "ftp://ftp.sunet.se/pub/gnu/"
- "ftp://sunsite.cnlab-switch.ch/mirror/gnu/"
- "ftp://ftp.ulak.net.tr/gnu/"
- "ftp://ftp.gnu.org.ua"
- "ftp://ftp.mcc.ac.uk/pub/gnu/"
- "ftp://ftp.mirror.ac.uk/sites/ftp.gnu.org/gnu/"
- "ftp://ftp.warwick.ac.uk/pub/gnu/"
- "ftp://ftp.hands.com/ftp.gnu.org/"
- "ftp://gnu.teleglobe.net/ftp.gnu.org/"])
+ "http://ftpmirror.gnu.org"])
("GNU Project Home Page" . "www.gnu.org")
;; Emacs.
@@ -233,7 +109,7 @@
[simple-query "wikipedia.org" "wikipedia.org/wiki/" ""])
;; Misc. general interest.
- ("Interactive Weather Information Network" . webjump-to-iwin)
+ ("National Weather Service" . webjump-to-iwin)
("Usenet FAQs" .
"www.faqs.org/faqs/")
("RTFM Usenet FAQs by Group" .
@@ -254,10 +130,10 @@
"www.neilvandyke.org/webjump/")
)
- "Sample hotlist for WebJump. See the documentation for the `webjump'
-function and the `webjump-sites' variable.")
+ "Sample hotlist for WebJump.
+See the documentation for `webjump' and `webjump-sites'.")
-(defvar webjump-state-to-postal-alist
+(defconst webjump-state-to-postal-alist
'(("Alabama" . "al") ("Alaska" . "ak") ("Arizona" . "az") ("Arkansas" . "ar")
("California" . "ca") ("Colorado" . "co") ("Connecticut" . "ct")
("Delaware" . "de") ("Florida" . "fl") ("Georgia" . "ga") ("Hawaii" . "hi")
@@ -277,8 +153,7 @@ function and the `webjump-sites' variable.")
;;------------------------------------------------------------ Option Variables
-(defvar webjump-sites
- webjump-sample-sites
+(defcustom webjump-sites webjump-sample-sites
"Hotlist for WebJump.
The hotlist is represented as an association list, with the CAR of each cell
@@ -309,33 +184,47 @@ parameter. This might come in handy for various kludges.
For convenience, if the `http://', `ftp://', or `file://' prefix is missing
from a URL, WebJump will make a guess at what you wanted and prepend it before
-submitting the URL.")
+submitting the URL."
+ :type '(alist :key-type (string :tag "Name")
+ :value-type (choice :tag "URL"
+ (string :tag "URL")
+ function
+ (vector :tag "Builtin"
+ (symbol :tag "Name")
+ (repeat :inline t :tag "Arguments"
+ string))
+ (sexp :tag "Expression to eval"))))
;;------------------------------------------------------- Sample Site Functions
(defun webjump-to-iwin (name)
- (let ((prefix "http://iwin.nws.noaa.gov/")
- (state (webjump-read-choice name "state"
- (append '(("Puerto Rico" . "pr"))
- webjump-state-to-postal-alist))))
- (if state
- (concat prefix "iwin/" state "/"
- (webjump-read-choice name "option"
- '(("Hourly Report" . "hourly")
- ("State Forecast" . "state")
- ("Local Forecast" . "local")
- ("Zone Forecast" . "zone")
- ("Short-Term Forecast" . "shortterm")
- ("Weather Summary" . "summary")
- ("Public Information" . "public")
- ("Climatic Data" . "climate")
- ("Aviation Products" . "aviation")
- ("Hydro Products" . "hydro")
- ("Special Weather" . "special")
- ("Watches and Warnings" . "warnings"))
- "zone")
- ".html")
- prefix)))
+ (let* ((prefix "http://www.nws.noaa.gov/view/")
+ (state (webjump-read-choice name "state"
+ (append '(("Puerto Rico" . "pr")
+ ("Guam" . "gu")
+ ("American Samoa" . "as")
+ ("District of Columbia" . "dc")
+ ("US Virgin Islands" . "vi"))
+ webjump-state-to-postal-alist)))
+ (opt (if state
+ (webjump-read-choice
+ name "option"
+ '(("Hourly Report" . "hourly")
+ ("State Forecast" . "state")
+ ("Zone Forecast" . "zone")
+ ("Short-Term Forecast" . "shortterm")
+ ("Forecast Discussion" . "discussion")
+ ("Weather Summary" . "summary")
+ ("Public Information" . "public")
+ ("Climatic Data" . "climate")
+ ("Hydro Products" . "hydro")
+ ("Watches" . "watches")
+ ("Special Weather" . "special")
+ ("Warnings and Advisories" . "warnings")
+ ("Fire Weather" . "firewx"))))))
+ (cond (opt (concat prefix "prodsByState.php?state=" state "&prodtype=" opt))
+ (state (concat prefix "states.php?state=" state))
+ (t prefix))))
(defun webjump-to-risks (name)
(let (issue volume)