From: Phil Sainty Date: Mon, 21 Oct 2019 11:05:50 +0000 (+1300) Subject: Support loading so-long.el on top of an earlier version X-Git-Tag: emacs-27.0.90~626^2^2~1 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=a94f961e625aa53deaf8605f892fd8993a4f0cb8;p=emacs.git Support loading so-long.el on top of an earlier version * so-long.el (so-long-version, so-long--latest-version): New variables. This enables users to safely load version 1.0 of so-long.el on top of an earlier version, as well as making provisions for doing likewise following any incompatible changes arising in future versions. --- diff --git a/lisp/so-long.el b/lisp/so-long.el index 982a699667a..2d551affa18 100644 --- a/lisp/so-long.el +++ b/lisp/so-long.el @@ -411,6 +411,8 @@ (add-to-list 'customize-package-emacs-version-alist '(so-long ("1.0" . "27.1"))) +(defconst so-long--latest-version "1.0") + (declare-function longlines-mode "longlines") (defvar longlines-mode) @@ -1818,6 +1820,54 @@ If it appears in `%s', you should remove it." (cdr hookfunc))) (make-obsolete (car hookfunc) nil "so-long.el version 1.0"))) +;; Live upgrades, for when a newer version is loaded over an older one. +;; +;; If `so-long-version' was already bound then that tells us which version we +;; should upgrade from. If `so-long-version' is unbound then most likely there +;; was no older version loaded; however, prior to version 1.0 `so-long-version' +;; was not defined at all, and so we also need to detect that scenario, which +;; we can do by testing for the presence of a symbol which was removed in 1.0. +;; +;; The variable `so-long-mode-enabled' covers versions 0.5 - 0.7.6, which is +;; every pre-1.0 release using the name "so-long.el". +(defvar so-long-version (if (boundp 'so-long-mode-enabled) + "0.5" ;; >= 0.5 and < 1.0 + so-long--latest-version) + "The loaded version of so-long.el.") + +;; Version-specific updates. +(when (version< so-long-version so-long--latest-version) + ;; Perform each update in sequence, as necessary. + ;; Update to version 1.0 from earlier versions: + (when (version< so-long-version "1.0") + (remove-hook 'change-major-mode-hook 'so-long-change-major-mode) + (require 'advice) + (when (ad-find-advice 'hack-local-variables 'after 'so-long--file-local-mode) + (ad-remove-advice 'hack-local-variables 'after 'so-long--file-local-mode) + (ad-activate 'hack-local-variables)) + (when (ad-find-advice 'set-auto-mode 'around 'so-long--set-auto-mode) + (ad-remove-advice 'set-auto-mode 'around 'so-long--set-auto-mode) + (ad-activate 'set-auto-mode)) + (when (boundp 'so-long-mode-map) + (define-key so-long-mode-map [remap so-long-mode-revert] #'so-long-revert)) + (dolist (var '(so-long-mode--inhibited + so-long-original-mode)) + (makunbound var)) + (dolist (func '(so-long-change-major-mode + so-long-check-header-modes + so-long-line-detected-p)) + (fmakunbound func)) + (defvar so-long-mode-enabled) + (when so-long-mode-enabled + (unless global-so-long-mode + (global-so-long-mode 1))) + (makunbound 'so-long-mode-enabled)) + ;; Update to version 1.N: + ;; (when (version< so-long-version "1.N") ...) + ;; + ;; All updates completed. + (setq so-long-version so-long--latest-version)) + (provide 'so-long)