emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

scratch/handler-bind 8f090cd421d 05/12: tramp.el: Use `handler-bind` ins


From: Stefan Monnier
Subject: scratch/handler-bind 8f090cd421d 05/12: tramp.el: Use `handler-bind` instead of `signal-hook-function`
Date: Mon, 25 Dec 2023 23:56:51 -0500 (EST)

branch: scratch/handler-bind
commit 8f090cd421dfcc6bdf993ac4429b0823dd75fc9d
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>

    tramp.el: Use `handler-bind` instead of `signal-hook-function`
    
    * lisp/net/tramp.el (tramp--trace-errors): Rename from
    `tramp-signal-hook-function` and change calling convention for
    `handler-bind`.
    (tramp-unknown-id-string, tramp-unknown-id-integer):
    Don't use `defconst` for vars which we let-bind (in tramp-tests.el).
    (tramp-file-name-handler): Use `handler-bind` instead of let-binding
    `signal-hook-function`.
    (tramp-handle-lock-file, tramp-handle-load, tramp-add-hops)
    (tramp-run-real-handler):
    * lisp/net/tramp-sshfs.el (tramp-sshfs-handle-insert-file-contents):
    * lisp/net/tramp-sh.el (tramp-sh-get-signal-strings):
    (tramp-send-command-and-read):
    * lisp/net/tramp-message.el (tramp-debug-message, tramp-error):
    * lisp/net/tramp-adb.el (tramp-do-parse-file-attributes-with-ls): Don't
    let-bind `signal-hook-function`.
---
 lisp/net/tramp-adb.el     |  4 +---
 lisp/net/tramp-message.el |  5 ++---
 lisp/net/tramp-sh.el      | 15 ++++++---------
 lisp/net/tramp-sshfs.el   |  2 +-
 lisp/net/tramp.el         | 30 ++++++++++++++----------------
 5 files changed, 24 insertions(+), 32 deletions(-)

diff --git a/lisp/net/tramp-adb.el b/lisp/net/tramp-adb.el
index e4d3ba8c74b..0b68e7384b2 100644
--- a/lisp/net/tramp-adb.el
+++ b/lisp/net/tramp-adb.el
@@ -297,9 +297,7 @@ arguments to pass to the OPERATION."
                 (cons uid tramp-unknown-id-integer)
                 (cons gid tramp-unknown-id-integer)
                 tramp-time-dont-know   ; atime
-                ;; `date-to-time' checks `iso8601-parse', which might fail.
-                (let (signal-hook-function)
-                  (date-to-time date)) ; mtime
+                (date-to-time date)    ; mtime
                 tramp-time-dont-know   ; ctime
                 size
                 mod-string
diff --git a/lisp/net/tramp-message.el b/lisp/net/tramp-message.el
index e05357f1f4f..924f4d15ad2 100644
--- a/lisp/net/tramp-message.el
+++ b/lisp/net/tramp-message.el
@@ -207,8 +207,7 @@ Message is formatted with FMT-STRING as control string and 
the remaining
 ARGUMENTS to actually emit the message (if applicable)."
   (declare (tramp-suppress-trace t))
   (let ((inhibit-message t)
-       create-lockfiles file-name-handler-alist message-log-max
-       signal-hook-function)
+       create-lockfiles file-name-handler-alist message-log-max)
     (with-current-buffer (tramp-get-debug-buffer vec)
       (goto-char (point-max))
       (let ((point (point)))
@@ -364,7 +363,7 @@ VEC-OR-PROC identifies the connection to use, SIGNAL is the
 signal identifier to be raised, remaining arguments passed to
 `tramp-message'.  Finally, signal SIGNAL is raised with
 FMT-STRING and ARGUMENTS."
-  (let (signal-hook-function)
+  (let ()
     (tramp-backtrace vec-or-proc)
     (unless arguments
       ;; FMT-STRING could be just a file name, as in
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el
index 1777e2f1ed8..94408db771f 100644
--- a/lisp/net/tramp-sh.el
+++ b/lisp/net/tramp-sh.el
@@ -3186,12 +3186,11 @@ implementation will be used."
        (setcdr signals (cddr signals)))
       ;; Sanity check.  "kill -l" shall have returned just the signal
       ;; names.  Some shells don't, like the one in "docker alpine".
-      (let (signal-hook-function)
-       (condition-case nil
-           (dolist (sig (cdr signals))
-             (unless (string-match-p (rx bol (+ (any "+-" alnum)) eol) sig)
-               (error nil)))
-         (error (setq signals '(0)))))
+      (condition-case nil
+         (dolist (sig (cdr signals))
+           (unless (string-match-p (rx bol (+ (any "+-" alnum)) eol) sig)
+             (error nil)))
+       (error (setq signals '(0))))
       (dotimes (i 128)
        (push
         (cond
@@ -5536,9 +5535,7 @@ raises an error."
       ;; Read the expression.
       (condition-case nil
          (prog1
-             (let ((signal-hook-function
-                    (unless noerror signal-hook-function)))
-               (read (current-buffer)))
+             (read (current-buffer))
            ;; Error handling.
            (when (search-forward-regexp (rx (not space)) (line-end-position) t)
              (error nil)))
diff --git a/lisp/net/tramp-sshfs.el b/lisp/net/tramp-sshfs.el
index 102ba637f55..afc2033ee6e 100644
--- a/lisp/net/tramp-sshfs.el
+++ b/lisp/net/tramp-sshfs.el
@@ -242,7 +242,7 @@ arguments to pass to the OPERATION."
   (filename &optional visit beg end replace)
   "Like `insert-file-contents' for Tramp files."
   (setq filename (expand-file-name filename))
-  (let (signal-hook-function result)
+  (let (result)
     (unwind-protect
         (setq result
              (insert-file-contents
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index 0207805c720..a8d4ea51fbe 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -1085,10 +1085,10 @@ Derived from `tramp-postfix-host-format'.")
 (defconst tramp-localname-regexp (rx (* (not (any "\r\n"))) eos)
   "Regexp matching localnames.")
 
-(defconst tramp-unknown-id-string "UNKNOWN"
+(defvar tramp-unknown-id-string "UNKNOWN"
   "String used to denote an unknown user or group.")
 
-(defconst tramp-unknown-id-integer -1
+(defvar tramp-unknown-id-integer -1
   "Integer used to denote an unknown user or group.")
 
 ;;;###tramp-autoload
@@ -1994,16 +1994,16 @@ does not exist, otherwise propagate the error."
 
 ;; This function provides traces in case of errors not triggered by
 ;; Tramp functions.
-(defun tramp-signal-hook-function (error-symbol data)
-  "Function to be called via `signal-hook-function'."
+(defun tramp--trace-errors (err)
+  "Function to be called via `handler-bind'."
   ;; `custom-initialize-*' functions provoke `void-variable' errors.
   ;; We don't want to see them in the backtrace.
   (declare (tramp-suppress-trace t))
-  (unless (eq error-symbol 'void-variable)
+  (unless (eq (car err) 'void-variable)
     (let ((inhibit-message t))
       (tramp-error
-       (car tramp-current-connection) error-symbol
-       (mapconcat (lambda (x) (format "%s" x)) data " ")))))
+       (car tramp-current-connection) (car err)
+       (mapconcat (lambda (x) (format "%s" x)) (cdr err) " ")))))
 
 (defmacro with-parsed-tramp-file-name (filename var &rest body)
   "Parse a Tramp filename and make components available in the body.
@@ -2081,7 +2081,7 @@ without a visible progress reporter."
 (defmacro with-tramp-timeout (list &rest body)
   "Like `with-timeout', but allow SECONDS to be nil.
 
-(fn (SECONDS TIMEOUT-FORMS...) BODY)"
+\(fn (SECONDS TIMEOUT-FORMS...) BODY)"
   (declare (indent 1) (debug ((form body) body)))
   (let ((seconds (car list))
        (timeout-forms (cdr list)))
@@ -2248,8 +2248,7 @@ arguments to pass to the OPERATION."
            ,(and (eq inhibit-file-name-operation operation)
                  inhibit-file-name-handlers)))
         (inhibit-file-name-operation operation)
-        (args (if (tramp-file-name-p (car args)) (cons nil (cdr args)) args))
-        signal-hook-function)
+        (args (if (tramp-file-name-p (car args)) (cons nil (cdr args)) args)))
     (apply operation args)))
 
 ;; We handle here all file primitives.  Most of them have the file
@@ -2386,8 +2385,8 @@ Fall back to normal file name handler if no Tramp file 
name handler exists."
             (let ((current-connection tramp-current-connection)
                  (foreign
                   (tramp-find-foreign-file-name-handler v operation))
-                 (signal-hook-function #'tramp-signal-hook-function)
                  result)
+             (handler-bind ((error #'tramp--trace-errors))
              ;; Set `tramp-current-connection'.
              (unless
                  (tramp-file-name-equal-p v (car tramp-current-connection))
@@ -2453,7 +2452,7 @@ Fall back to normal file name handler if no Tramp file 
name handler exists."
                (unless
                    (tramp-file-name-equal-p
                     (car current-connection) (car tramp-current-connection))
-                 (setq tramp-current-connection current-connection))))))
+                 (setq tramp-current-connection current-connection)))))))
 
       ;; When `tramp-mode' is not enabled, or the file name is quoted,
       ;; we don't do anything.
@@ -4584,7 +4583,7 @@ Do not set it manually, it is used buffer-local in 
`tramp-get-lock-pid'.")
 
        ;; Do the lock.
         (let ((tramp-verbose 0)
-              create-lockfiles signal-hook-function)
+              create-lockfiles)
          (condition-case nil
              (make-symbolic-link info lockname 'ok-if-already-exists)
            (error
@@ -4632,8 +4631,7 @@ Do not set it manually, it is used buffer-local in 
`tramp-get-lock-pid'.")
       (tramp-error v 'file-missing file))
     (if (not (file-exists-p file))
        nil
-      (let ((signal-hook-function (unless noerror signal-hook-function))
-           (inhibit-message (or inhibit-message nomessage)))
+      (let ((inhibit-message (or inhibit-message nomessage)))
        (with-tramp-progress-reporter v 0 (format "Loading %s" file)
          (let ((local-copy (file-local-copy file)))
            (unwind-protect
@@ -4651,7 +4649,7 @@ Do not set it manually, it is used buffer-local in 
`tramp-get-lock-pid'.")
   "Add ad-hoc proxy definitions to `tramp-default-proxies-alist'."
   (when-let ((hops (tramp-file-name-hop vec))
             (item vec))
-    (let (signal-hook-function changed)
+    (let (changed)
       (dolist
          (proxy (reverse (split-string hops tramp-postfix-hop-regexp 'omit)))
        (let* ((host-port (tramp-file-name-host-port item))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]