From 69c2b3d29ed83254ab17ceabc5b93abe153beaf0 Mon Sep 17 00:00:00 2001 From: Andreas Gerler Date: Tue, 13 Nov 2018 12:23:12 +0100 Subject: [PATCH] update impatient-mode. Signed-off-by: Andreas Gerler --- .../impatient-mode-pkg.el | 8 - elpa/impatient-mode-20150501.247/index.html | 110 ------------- elpa/impatient-mode-20150501.247/loading.html | 9 -- .../impatient-mode-autoloads.el | 15 +- .../impatient-mode-pkg.el | 12 ++ .../impatient-mode.el | 145 +++++++++++++----- elpa/impatient-mode-20181002.1231/index.html | 114 ++++++++++++++ .../jquery.js | 0 .../impatient-mode-20181002.1231/loading.html | 3 + 9 files changed, 242 insertions(+), 174 deletions(-) delete mode 100644 elpa/impatient-mode-20150501.247/impatient-mode-pkg.el delete mode 100644 elpa/impatient-mode-20150501.247/index.html delete mode 100644 elpa/impatient-mode-20150501.247/loading.html rename elpa/{impatient-mode-20150501.247 => impatient-mode-20181002.1231}/impatient-mode-autoloads.el (50%) create mode 100644 elpa/impatient-mode-20181002.1231/impatient-mode-pkg.el rename elpa/{impatient-mode-20150501.247 => impatient-mode-20181002.1231}/impatient-mode.el (65%) create mode 100644 elpa/impatient-mode-20181002.1231/index.html rename elpa/{impatient-mode-20150501.247 => impatient-mode-20181002.1231}/jquery.js (100%) create mode 100644 elpa/impatient-mode-20181002.1231/loading.html diff --git a/elpa/impatient-mode-20150501.247/impatient-mode-pkg.el b/elpa/impatient-mode-20150501.247/impatient-mode-pkg.el deleted file mode 100644 index 094bc919..00000000 --- a/elpa/impatient-mode-20150501.247/impatient-mode-pkg.el +++ /dev/null @@ -1,8 +0,0 @@ -(define-package "impatient-mode" "20150501.247" "Serve buffers live over HTTP" - '((cl-lib "0.3") - (simple-httpd "1.4.0") - (htmlize "1.40")) - :url "https://github.com/netguy204/imp.el") -;; Local Variables: -;; no-byte-compile: t -;; End: diff --git a/elpa/impatient-mode-20150501.247/index.html b/elpa/impatient-mode-20150501.247/index.html deleted file mode 100644 index 6d92b0b9..00000000 --- a/elpa/impatient-mode-20150501.247/index.html +++ /dev/null @@ -1,110 +0,0 @@ - - - - - - - - - - - - - diff --git a/elpa/impatient-mode-20150501.247/loading.html b/elpa/impatient-mode-20150501.247/loading.html deleted file mode 100644 index a2690df6..00000000 --- a/elpa/impatient-mode-20150501.247/loading.html +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - -

Loading Content

- - diff --git a/elpa/impatient-mode-20150501.247/impatient-mode-autoloads.el b/elpa/impatient-mode-20181002.1231/impatient-mode-autoloads.el similarity index 50% rename from elpa/impatient-mode-20150501.247/impatient-mode-autoloads.el rename to elpa/impatient-mode-20181002.1231/impatient-mode-autoloads.el index 20a7c9d9..ddcd0d2a 100644 --- a/elpa/impatient-mode-20150501.247/impatient-mode-autoloads.el +++ b/elpa/impatient-mode-20181002.1231/impatient-mode-autoloads.el @@ -1,10 +1,13 @@ ;;; impatient-mode-autoloads.el --- automatically extracted autoloads ;; ;;; Code: -(add-to-list 'load-path (or (file-name-directory #$) (car load-path))) + +(add-to-list 'load-path (directory-file-name + (or (file-name-directory #$) (car load-path)))) + -;;;### (autoloads nil "impatient-mode" "impatient-mode.el" (21908 -;;;;;; 14231 0 0)) +;;;### (autoloads nil "impatient-mode" "impatient-mode.el" (0 0 0 +;;;;;; 0)) ;;; Generated autoloads from impatient-mode.el (autoload 'impatient-mode "impatient-mode" "\ @@ -12,10 +15,11 @@ Serves the buffer live over HTTP. \(fn &optional ARG)" t nil) +(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "impatient-mode" '("httpd/imp" "imp"))) + ;;;*** -;;;### (autoloads nil nil ("impatient-mode-pkg.el") (21908 14231 -;;;;;; 202947 0)) +;;;### (autoloads nil nil ("impatient-mode-pkg.el") (0 0 0 0)) ;;;*** @@ -23,5 +27,6 @@ Serves the buffer live over HTTP. ;; version-control: never ;; no-byte-compile: t ;; no-update-autoloads: t +;; coding: utf-8 ;; End: ;;; impatient-mode-autoloads.el ends here diff --git a/elpa/impatient-mode-20181002.1231/impatient-mode-pkg.el b/elpa/impatient-mode-20181002.1231/impatient-mode-pkg.el new file mode 100644 index 00000000..b369bdda --- /dev/null +++ b/elpa/impatient-mode-20181002.1231/impatient-mode-pkg.el @@ -0,0 +1,12 @@ +(define-package "impatient-mode" "20181002.1231" "Serve buffers live over HTTP" + '((cl-lib "0.3") + (simple-httpd "1.5.0") + (htmlize "1.40")) + :authors + '(("Brian Taylor" . "el.wubo@gmail.com")) + :maintainer + '("Brian Taylor" . "el.wubo@gmail.com") + :url "https://github.com/netguy204/imp.el") +;; Local Variables: +;; no-byte-compile: t +;; End: diff --git a/elpa/impatient-mode-20150501.247/impatient-mode.el b/elpa/impatient-mode-20181002.1231/impatient-mode.el similarity index 65% rename from elpa/impatient-mode-20150501.247/impatient-mode.el rename to elpa/impatient-mode-20181002.1231/impatient-mode.el index 0e41363c..64489079 100644 --- a/elpa/impatient-mode-20150501.247/impatient-mode.el +++ b/elpa/impatient-mode-20181002.1231/impatient-mode.el @@ -1,16 +1,16 @@ -;;; impatient-mode.el --- Serve buffers live over HTTP +;;; impatient-mode.el --- Serve buffers live over HTTP -*- lexical-binding: t; -*- ;; This is free and unencumbered software released into the public domain. ;; Author: Brian Taylor -;; Version: 1.0.0 +;; Version: 1.1 ;; URL: https://github.com/netguy204/imp.el -;; Package-Requires: ((cl-lib "0.3") (simple-httpd "1.4.0") (htmlize "1.40")) +;; Package-Requires: ((cl-lib "0.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/. To +;; 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 @@ -47,24 +47,31 @@ (defvar impatient-mode-map (make-sparse-keymap) "Keymap for impatient-mode.") -(make-variable-buffer-local - (defvar imp-user-filter #'imp-htmlize-filter - "Per buffer html-producing function by user.")) +(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") -(make-variable-buffer-local - (defvar imp-client-list () - "List of client processes watching the current buffer.")) +(defvar-local imp--idle-timer nil + "A timer that goes off after `impatient-mode-delay' seconds of inactivity") -(make-variable-buffer-local - (defvar imp-last-state 0 - "State sequence number.")) +(defvar-local imp-user-filter #'imp-htmlize-filter + "Per buffer html-producing function by user.") -(make-variable-buffer-local - (defvar imp-related-files nil - "Files that seem to be related to this buffer")) +(defvar-local imp-client-list () + "List of client processes watching the current buffer.") + +(defvar-local imp-last-state 0 + "State sequence number.") + +(defvar-local imp-related-files nil + "Files that seem to be related to this buffer") + +(defvar-local imp--buffer-dirty-p nil + "If non-nil, buffer has been modified but not sent to clients.") (defvar imp-default-user-filters - '((html-mode . nil) + '((mhtml-mode . nil) + (html-mode . nil) (web-mode . nil)) "Alist indicating which filter should be used for which modes.") @@ -75,8 +82,11 @@ :lighter " imp" :keymap impatient-mode-map (if (not impatient-mode) - (remove-hook 'after-change-functions 'imp--on-change t) - (add-hook 'after-change-functions 'imp--on-change nil t) + (progn + (imp--cleanup-timer) + (remove-hook 'after-change-functions #'imp--on-change t)) + (add-hook 'kill-buffer-hook #'imp--cleanup-timer nil t) + (add-hook 'after-change-functions #'imp--on-change nil t) (imp-remove-user-filter))) (defvar imp-shim-root (file-name-directory load-file-name) @@ -115,13 +125,18 @@ buffer." (imp-set-user-filter nil) (imp-set-user-filter 'imp-htmlize-filter))) -(defun imp-visit-buffer () - "Visit the buffer in a browser." - (interactive) - (impatient-mode) - (browse-url - (format "http://%s:%d/imp/live/%s/" - (system-name) httpd-port (url-hexify-string (buffer-name))))) +(defun imp-visit-buffer (&optional arg) + "Visit the current buffer in a browser. +If given a prefix argument, 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))) + (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." @@ -137,7 +152,7 @@ buffer." (member mime-type '("text/css" "text/html" "text/xml" "text/plain" "text/javascript")))) -(defun httpd/imp/static (proc path query req) +(defun httpd/imp/static (proc path _query req) "Serve up static files." (let* ((file (file-name-nondirectory path)) (clean (expand-file-name file imp-shim-root))) @@ -165,10 +180,11 @@ buffer." (httpd-error proc 403 (format "Buffer %s is private or doesn't exist." buffer-name))) -(defun httpd/imp/live (proc path query req) +(defun httpd/imp/live (proc path _query req) "Serve up the shim that lets us watch a buffer change" (let* ((index (expand-file-name "index.html" imp-shim-root)) - (parts (cdr (split-string path "/"))) + (decoded (url-unhex-string path)) + (parts (cdr (split-string decoded "/"))) (buffer-name (nth 2 parts)) (file (httpd-clean-path (mapconcat 'identity (nthcdr 3 parts) "/"))) (buffer (get-buffer buffer-name)) @@ -176,8 +192,8 @@ buffer." (buffer-dir (and buffer-file (file-name-directory buffer-file)))) (cond - ((equal (file-name-directory path) "/imp/live/") - (httpd-redirect proc (concat path "/"))) + ((equal (file-name-directory decoded) "/imp/live/") + (httpd-redirect proc (concat decoded "/"))) ((not (imp-buffer-enabled-p buffer)) (imp--private proc buffer-name)) ((and (not (string= file "./")) buffer-dir) (let* ((full-file-name (expand-file-name file buffer-dir)) @@ -185,11 +201,12 @@ buffer." (live-buffer (cl-remove-if-not (lambda (buf) (equal full-file-name (buffer-file-name buf))) (imp--buffer-list)))) - (add-to-list 'imp-related-files full-file-name) + (with-current-buffer buffer-name + (add-to-list 'imp-related-files full-file-name)) (if live-buffer (with-temp-buffer (insert-buffer-substring (cl-first live-buffer)) - (if (imp--should-not-cache-p path) + (if (imp--should-not-cache-p decoded) (httpd-send-header proc mime-type 200 :Cache-Control "no-cache") (httpd-send-header proc mime-type 200 @@ -198,7 +215,7 @@ buffer." (httpd-send-file proc full-file-name req)))) (t (imp-buffer-enabled-p buffer) (httpd-send-file proc index req))))) -(defun httpd/imp (proc path &rest args) +(defun httpd/imp (proc path &rest _) (cond ((equal path "/imp") (httpd-redirect proc "/imp/")) ((equal path "/imp/") (imp-serve-buffer-list proc)) @@ -217,7 +234,7 @@ buffer." :X-Imp-Count id)))) (defun imp--send-state-ignore-errors (proc) - (condition-case error-case + (condition-case _ (imp--send-state proc) (error nil))) @@ -225,23 +242,67 @@ buffer." (while imp-client-list (imp--send-state-ignore-errors (pop imp-client-list)))) -(defun imp--on-change (&rest args) - "Hook for after-change-functions." - (cl-incf imp-last-state) +(defun imp--cleanup-timer () + "Destroy any timer associated with this buffer." + (when imp--idle-timer + (cancel-timer (cdr imp--idle-timer)) + (setf imp--idle-timer nil))) +(defun imp--start-idle-timer () + "Start/update the idle timer as appropriate." + (cond + ;; Timer doesn't exist and shouldn't (do nothing) + ((and (null impatient-mode-delay) (null imp--idle-timer))) + ;; Timer exists when it shouldnt + ((and (null impatient-mode-delay) imp--idle-timer) + (cancel-timer (cdr imp--idle-timer)) + (setf imp--idle-timer nil)) + ;; Timer doesn't exist when it should + ((and impatient-mode-delay (null imp--idle-timer)) + (let* ((buffer (current-buffer)) + (timer (run-with-idle-timer + impatient-mode-delay :repeat + (lambda () + (with-current-buffer buffer + (imp--after-timeout)))))) + (setf imp--idle-timer (cons impatient-mode-delay timer)))) + ;; Timer delay is incorrect + ((not (eql (car imp--idle-timer) impatient-mode-delay)) + (timer-set-idle-time (cdr imp--idle-timer) + impatient-mode-delay + :repeat) + (setf (car imp--idle-timer) impatient-mode-delay)))) + +(defun imp--on-change (&rest _) + "Hook for `after-change-functions'." + (imp--start-idle-timer) + (if impatient-mode-delay + (setf imp--buffer-dirty-p :dirty) + (imp--update-buffer))) + +(defun imp--after-timeout () + "Executes after `impatient-mode-delay' seconds of idleness" + (when imp--buffer-dirty-p + (imp--update-buffer)) + (imp--start-idle-timer)) + +(defun imp--update-buffer () + "Update this buffer in the browser." + (setf imp--buffer-dirty-p nil) + (cl-incf imp-last-state) ;; notify our clients (imp--notify-clients) - - ;; notify any clients that we're in the imp-related-files list for + ;; notify any clients that we're in the `imp-related-files' list for (let ((buffer-file (buffer-file-name (current-buffer)))) (dolist (buffer (imp--buffer-list)) (with-current-buffer buffer (when (member buffer-file imp-related-files) (imp--notify-clients)))))) -(defun httpd/imp/buffer (proc path query &rest args) +(defun httpd/imp/buffer (proc path query &rest _) "Servlet that accepts long poll requests." - (let* ((buffer-name (file-name-nondirectory path)) + (let* ((decoded (url-unhex-string path)) + (buffer-name (file-name-nondirectory decoded)) (buffer (get-buffer buffer-name)) (req-last-id (string-to-number (or (cadr (assoc "id" query)) "0")))) (if (imp-buffer-enabled-p buffer) diff --git a/elpa/impatient-mode-20181002.1231/index.html b/elpa/impatient-mode-20181002.1231/index.html new file mode 100644 index 00000000..7ca9e953 --- /dev/null +++ b/elpa/impatient-mode-20181002.1231/index.html @@ -0,0 +1,114 @@ + + + + + + + + diff --git a/elpa/impatient-mode-20150501.247/jquery.js b/elpa/impatient-mode-20181002.1231/jquery.js similarity index 100% rename from elpa/impatient-mode-20150501.247/jquery.js rename to elpa/impatient-mode-20181002.1231/jquery.js diff --git a/elpa/impatient-mode-20181002.1231/loading.html b/elpa/impatient-mode-20181002.1231/loading.html new file mode 100644 index 00000000..4a66cf80 --- /dev/null +++ b/elpa/impatient-mode-20181002.1231/loading.html @@ -0,0 +1,3 @@ + + +

Loading Content

-- 2.47.3