From b8b75466e42171e9466ab07fc0c8535f3f2ee78a Mon Sep 17 00:00:00 2001 From: Andreas Gerler Date: Sat, 17 Dec 2022 20:14:07 +0100 Subject: [PATCH] update impatient mode Signed-off-by: Andreas Gerler --- .../impatient-mode-autoloads.el | 18 +++- .../impatient-mode-pkg.el | 6 +- .../impatient-mode.el | 91 +++++++++++-------- .../index.html | 0 .../jquery.js | 0 .../loading.html | 0 6 files changed, 71 insertions(+), 44 deletions(-) rename elpa/{impatient-mode-20181002.1231 => impatient-mode-20200723.2117}/impatient-mode-autoloads.el (51%) rename elpa/{impatient-mode-20181002.1231 => impatient-mode-20200723.2117}/impatient-mode-pkg.el (64%) rename elpa/{impatient-mode-20181002.1231 => impatient-mode-20200723.2117}/impatient-mode.el (81%) rename elpa/{impatient-mode-20181002.1231 => impatient-mode-20200723.2117}/index.html (100%) rename elpa/{impatient-mode-20181002.1231 => impatient-mode-20200723.2117}/jquery.js (100%) rename elpa/{impatient-mode-20181002.1231 => impatient-mode-20200723.2117}/loading.html (100%) diff --git a/elpa/impatient-mode-20181002.1231/impatient-mode-autoloads.el b/elpa/impatient-mode-20200723.2117/impatient-mode-autoloads.el similarity index 51% rename from elpa/impatient-mode-20181002.1231/impatient-mode-autoloads.el rename to elpa/impatient-mode-20200723.2117/impatient-mode-autoloads.el index ddcd0d2a..6f04180a 100644 --- a/elpa/impatient-mode-20181002.1231/impatient-mode-autoloads.el +++ b/elpa/impatient-mode-20200723.2117/impatient-mode-autoloads.el @@ -1,4 +1,4 @@ -;;; impatient-mode-autoloads.el --- automatically extracted autoloads +;;; impatient-mode-autoloads.el --- automatically extracted autoloads -*- lexical-binding: t -*- ;; ;;; Code: @@ -13,9 +13,23 @@ (autoload 'impatient-mode "impatient-mode" "\ Serves the buffer live over HTTP. +This is a minor mode. If called interactively, toggle the +`impatient mode' mode. If the prefix argument is positive, +enable the mode, and if it is zero or negative, disable the mode. + +If called from Lisp, toggle the mode if ARG is `toggle'. Enable +the mode if ARG is nil, omitted, or is a positive number. +Disable the mode if ARG is a negative number. + +To check whether the minor mode is enabled in the current buffer, +evaluate `impatient-mode'. + +The mode's hook is called both when the mode is enabled and when +it is disabled. + \(fn &optional ARG)" t nil) -(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "impatient-mode" '("httpd/imp" "imp"))) +(register-definition-prefixes "impatient-mode" '("httpd/imp" "imp")) ;;;*** diff --git a/elpa/impatient-mode-20181002.1231/impatient-mode-pkg.el b/elpa/impatient-mode-20200723.2117/impatient-mode-pkg.el similarity index 64% rename from elpa/impatient-mode-20181002.1231/impatient-mode-pkg.el rename to elpa/impatient-mode-20200723.2117/impatient-mode-pkg.el index b369bdda..b727c70d 100644 --- a/elpa/impatient-mode-20181002.1231/impatient-mode-pkg.el +++ b/elpa/impatient-mode-20200723.2117/impatient-mode-pkg.el @@ -1,8 +1,8 @@ -(define-package "impatient-mode" "20181002.1231" "Serve buffers live over HTTP" - '((cl-lib "0.3") +(define-package "impatient-mode" "20200723.2117" "Serve buffers live over HTTP" + '((emacs "24.3") (simple-httpd "1.5.0") (htmlize "1.40")) - :authors + :commit "cbddfd54242210df3e1c3b590fada5bb5423f5ed" :authors '(("Brian Taylor" . "el.wubo@gmail.com")) :maintainer '("Brian Taylor" . "el.wubo@gmail.com") diff --git a/elpa/impatient-mode-20181002.1231/impatient-mode.el b/elpa/impatient-mode-20200723.2117/impatient-mode.el similarity index 81% rename from elpa/impatient-mode-20181002.1231/impatient-mode.el rename to elpa/impatient-mode-20200723.2117/impatient-mode.el index 64489079..3537e938 100644 --- a/elpa/impatient-mode-20181002.1231/impatient-mode.el +++ b/elpa/impatient-mode-20200723.2117/impatient-mode.el @@ -5,23 +5,23 @@ ;; Author: Brian Taylor ;; Version: 1.1 ;; URL: https://github.com/netguy204/imp.el -;; Package-Requires: ((cl-lib "0.3") (simple-httpd "1.5.0") (htmlize "1.40")) +;; Package-Requires: ((emacs "24.3") (simple-httpd "1.5.0") (htmlize "1.40")) ;;; Commentary: ;; impatient-mode is a minor mode that publishes the live buffer -;; through the local simple-httpd server under /imp/live//. To -;; unpublish a buffer, toggle impatient-mode off. +;; through the local simple-httpd server under /imp/live//. +;; To unpublish a buffer, toggle impatient-mode off. ;; Start the simple-httpd server (`httpd-start') and visit /imp/ on -;; the local server. There will be a listing of all the buffers that -;; currently have impatient-mode enabled. This is likely to be found +;; the local server. There will be a listing of all the buffers that +;; currently have impatient-mode enabled. This is likely to be found ;; here: ;; http://localhost:8080/imp/ ;; Except for html-mode buffers, buffers will be prettied up with -;; htmlize before being sent to clients. This can be toggled at any +;; htmlize before being sent to clients. This can be toggled at any ;; time with `imp-toggle-htmlize'. ;; Because html-mode buffers are sent raw, you can use impatient-mode @@ -29,8 +29,8 @@ ;; primary motivation of this mode. ;; To receive updates the browser issues a long poll on the client -;; waiting for the buffer to change -- server push. The response -;; happens in an `after-change-functions' hook. Buffers that do not +;; waiting for the buffer to change -- server push. The response +;; happens in an `after-change-functions' hook. Buffers that do not ;; run these hooks will not be displayed live to clients. ;;; Code: @@ -40,16 +40,22 @@ (require 'simple-httpd) (require 'htmlize) -(defgroup impatient-mode nil +(defgroup impatient nil "Serve buffers live over HTTP." :group 'comm) -(defvar impatient-mode-map (make-sparse-keymap) - "Keymap for impatient-mode.") +(defcustom impatient-mode-delay nil + "The delay in seconds between a keypress and the browser reload. +Set to nil for no delay" + :group 'impatient + :type 'boolean) -(defvar impatient-mode-delay nil - "The delay in seconds between a keypress and the buffer being - reloaded in the browser. Set to nil for no delay") +(defcustom imp-default-user-filters '((mhtml-mode . nil) + (html-mode . nil) + (web-mode . nil)) + "Alist indicating which filter should be used for which modes." + :group 'impatient + :type 'sexp) (defvar-local imp--idle-timer nil "A timer that goes off after `impatient-mode-delay' seconds of inactivity") @@ -69,16 +75,13 @@ (defvar-local imp--buffer-dirty-p nil "If non-nil, buffer has been modified but not sent to clients.") -(defvar imp-default-user-filters - '((mhtml-mode . nil) - (html-mode . nil) - (web-mode . nil)) - "Alist indicating which filter should be used for which modes.") +(defvar impatient-mode-map (make-sparse-keymap) + "Keymap for impatient-mode.") ;;;###autoload (define-minor-mode impatient-mode "Serves the buffer live over HTTP." - :group 'impatient-mode + :group 'impatient :lighter " imp" :keymap impatient-mode-map (if (not impatient-mode) @@ -92,18 +95,18 @@ (defvar imp-shim-root (file-name-directory load-file-name) "Location of data files needed by impatient-mode.") -(defun imp-set-user-filter (function) - "Sets a user-defined filter for this buffer. +(defun imp-set-user-filter (fn) + "Set a FN as user-defined filter for this buffer. FUNCTION should accept one argument, the buffer to be filtered, and will be evaluated with the output buffer set as the current buffer." (interactive "aCustom filter: ") - (setq imp-user-filter function) + (setq imp-user-filter fn) (cl-incf imp-last-state) (imp--notify-clients)) (defun imp-remove-user-filter () - "Sets the user-defined filter for this buffer to the default." + "Set the user-defined filter for this buffer to the default." (interactive) (let ((lookup (assoc major-mode imp-default-user-filters))) (if lookup @@ -113,9 +116,9 @@ buffer." (imp--notify-clients)) (defun imp-htmlize-filter (buffer) - "Htmlization of buffers before sending to clients." + "Htmlize BUFFER before sending to clients." (let ((html-buffer (save-match-data (htmlize-buffer buffer)))) - (insert-buffer-substring html-buffer) + (princ (with-current-buffer html-buffer (buffer-string))) (kill-buffer html-buffer))) (defun imp-toggle-htmlize () @@ -127,27 +130,36 @@ buffer." (defun imp-visit-buffer (&optional arg) "Visit the current buffer in a browser. -If given a prefix argument, visit the buffer listing instead." +If given a prefix ARG, visit the buffer listing instead." (interactive "P") (unless (process-status "httpd") (httpd-start)) (unless impatient-mode (impatient-mode)) - (let ((url (format "http://%s:%d/imp/" (system-name) httpd-port))) + (let* ((proc (get-process "httpd")) + (proc-info (process-contact proc t)) + (raw-host (plist-get proc-info :host)) + (host (if (member raw-host + '(nil local "127.0.0.1" "::1" "0.0.0.0" "::")) + "localhost" + raw-host)) + (local-addr (plist-get proc-info :local)) + (port (aref local-addr (1- (length local-addr)))) + (url (format "http://%s:%d/imp/" host port))) (unless arg (setq url (format "%slive/%s/" url (url-hexify-string (buffer-name))))) (browse-url url))) (defun imp-buffer-enabled-p (buffer) - "Return t if buffer has impatient-mode enabled." + "Return t if BUFFER has impatient-mode enabled." (and buffer (with-current-buffer (get-buffer buffer) impatient-mode))) (defun imp--buffer-list () - "List of all buffers with impatient-mode enabled" + "List of all buffers with impatient-mode enabled." (cl-remove-if-not 'imp-buffer-enabled-p (buffer-list))) (defun imp--should-not-cache-p (path) - "True if the path should be stamped with a no-cache header" + "True if the PATH should be stamped with a no-cache header." (let ((mime-type (httpd-get-mime (file-name-extension path)))) (member mime-type '("text/css" "text/html" "text/xml" "text/plain" "text/javascript")))) @@ -181,7 +193,7 @@ If given a prefix argument, visit the buffer listing instead." (format "Buffer %s is private or doesn't exist." buffer-name))) (defun httpd/imp/live (proc path _query req) - "Serve up the shim that lets us watch a buffer change" + "Serve up the shim that lets us watch a buffer change." (let* ((index (expand-file-name "index.html" imp-shim-root)) (decoded (url-unhex-string path)) (parts (cdr (split-string decoded "/"))) @@ -226,12 +238,13 @@ If given a prefix argument, visit the buffer listing instead." (user-filter imp-user-filter) (buffer (current-buffer))) (with-temp-buffer - (if user-filter - (funcall user-filter buffer) - (insert-buffer-substring buffer)) - (httpd-send-header proc "text/html" 200 - :Cache-Control "no-cache" - :X-Imp-Count id)))) + (let ((standard-output (current-buffer))) + (if user-filter + (funcall user-filter buffer) + (insert-buffer-substring buffer)) + (httpd-send-header proc "text/html" 200 + :Cache-Control "no-cache" + :X-Imp-Count id))))) (defun imp--send-state-ignore-errors (proc) (condition-case _ @@ -281,7 +294,7 @@ If given a prefix argument, visit the buffer listing instead." (imp--update-buffer))) (defun imp--after-timeout () - "Executes after `impatient-mode-delay' seconds of idleness" + "Execute after `impatient-mode-delay' seconds of idleness." (when imp--buffer-dirty-p (imp--update-buffer)) (imp--start-idle-timer)) diff --git a/elpa/impatient-mode-20181002.1231/index.html b/elpa/impatient-mode-20200723.2117/index.html similarity index 100% rename from elpa/impatient-mode-20181002.1231/index.html rename to elpa/impatient-mode-20200723.2117/index.html diff --git a/elpa/impatient-mode-20181002.1231/jquery.js b/elpa/impatient-mode-20200723.2117/jquery.js similarity index 100% rename from elpa/impatient-mode-20181002.1231/jquery.js rename to elpa/impatient-mode-20200723.2117/jquery.js diff --git a/elpa/impatient-mode-20181002.1231/loading.html b/elpa/impatient-mode-20200723.2117/loading.html similarity index 100% rename from elpa/impatient-mode-20181002.1231/loading.html rename to elpa/impatient-mode-20200723.2117/loading.html -- 2.47.3