diff options
| author | Lars Ingebrigtsen | 2019-06-21 18:51:14 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2019-06-21 18:51:14 +0200 |
| commit | 9f64c4e8de4ade84bfb3d139ef2b832226235e45 (patch) | |
| tree | 715c4c8c62a74023c5518b239729adf931a05f7b | |
| parent | 436ccc6967146e5fbcf7a27a90fb44d0452cb901 (diff) | |
| download | emacs-9f64c4e8de4ade84bfb3d139ef2b832226235e45.tar.gz emacs-9f64c4e8de4ade84bfb3d139ef2b832226235e45.zip | |
Revert "Remove XEmacs compat code from savehist.el"
This reverts commit a97ba6eb305c9db8641c0e65748907cd53dbfa5e.
According to bug#36324, this broke savehist.el
| -rw-r--r-- | lisp/savehist.el | 65 |
1 files changed, 50 insertions, 15 deletions
diff --git a/lisp/savehist.el b/lisp/savehist.el index 6f79369f0c5..79ab8483868 100644 --- a/lisp/savehist.el +++ b/lisp/savehist.el | |||
| @@ -48,6 +48,8 @@ | |||
| 48 | ;;; Code: | 48 | ;;; Code: |
| 49 | 49 | ||
| 50 | (require 'custom) | 50 | (require 'custom) |
| 51 | (eval-when-compile | ||
| 52 | (if (featurep 'xemacs) (require 'cl))) | ||
| 51 | 53 | ||
| 52 | ;; User variables | 54 | ;; User variables |
| 53 | 55 | ||
| @@ -118,8 +120,12 @@ to save." | |||
| 118 | 120 | ||
| 119 | ;; This should be capable of representing characters used by Emacs. | 121 | ;; This should be capable of representing characters used by Emacs. |
| 120 | ;; We prefer UTF-8 over ISO 2022 because it is well-known outside | 122 | ;; We prefer UTF-8 over ISO 2022 because it is well-known outside |
| 121 | ;; Mule. | 123 | ;; Mule. XEmacs prior to 21.5 had UTF-8 provided by an external |
| 122 | (defvar savehist-coding-system 'utf-8-unix | 124 | ;; package which may not be loaded, which is why we check for version. |
| 125 | (defvar savehist-coding-system (if (and (featurep 'xemacs) | ||
| 126 | (<= emacs-major-version 21) | ||
| 127 | (< emacs-minor-version 5)) | ||
| 128 | 'iso-2022-8 'utf-8-unix) | ||
| 123 | "The coding system Savehist uses for saving the minibuffer history. | 129 | "The coding system Savehist uses for saving the minibuffer history. |
| 124 | Changing this value while Emacs is running is supported, but considered | 130 | Changing this value while Emacs is running is supported, but considered |
| 125 | unwise, unless you know what you are doing.") | 131 | unwise, unless you know what you are doing.") |
| @@ -141,6 +147,10 @@ along with minibuffer history. You can change its value off | |||
| 141 | This prevents toggling Savehist mode from destroying existing | 147 | This prevents toggling Savehist mode from destroying existing |
| 142 | minibuffer history.") | 148 | minibuffer history.") |
| 143 | 149 | ||
| 150 | (when (featurep 'xemacs) | ||
| 151 | ;; Must declare this under XEmacs, which doesn't have built-in | ||
| 152 | ;; minibuffer history truncation. | ||
| 153 | (defvar history-length 100)) | ||
| 144 | 154 | ||
| 145 | ;; Functions. | 155 | ;; Functions. |
| 146 | 156 | ||
| @@ -207,8 +217,12 @@ To undo this, call `savehist-uninstall'." | |||
| 207 | (when (and savehist-autosave-interval | 217 | (when (and savehist-autosave-interval |
| 208 | (null savehist-timer)) | 218 | (null savehist-timer)) |
| 209 | (setq savehist-timer | 219 | (setq savehist-timer |
| 210 | (run-with-timer savehist-autosave-interval | 220 | (if (featurep 'xemacs) |
| 211 | savehist-autosave-interval #'savehist-autosave)))) | 221 | (start-itimer |
| 222 | "savehist" #'savehist-autosave savehist-autosave-interval | ||
| 223 | savehist-autosave-interval) | ||
| 224 | (run-with-timer savehist-autosave-interval | ||
| 225 | savehist-autosave-interval #'savehist-autosave))))) | ||
| 212 | 226 | ||
| 213 | (defun savehist-uninstall () | 227 | (defun savehist-uninstall () |
| 214 | "Undo installing savehist. | 228 | "Undo installing savehist. |
| @@ -216,9 +230,15 @@ Normally invoked by calling `savehist-mode' to unset the minor mode." | |||
| 216 | (remove-hook 'minibuffer-setup-hook #'savehist-minibuffer-hook) | 230 | (remove-hook 'minibuffer-setup-hook #'savehist-minibuffer-hook) |
| 217 | (remove-hook 'kill-emacs-hook #'savehist-autosave) | 231 | (remove-hook 'kill-emacs-hook #'savehist-autosave) |
| 218 | (when savehist-timer | 232 | (when savehist-timer |
| 219 | (cancel-timer savehist-timer) | 233 | (if (featurep 'xemacs) |
| 234 | (delete-itimer savehist-timer) | ||
| 235 | (cancel-timer savehist-timer)) | ||
| 220 | (setq savehist-timer nil))) | 236 | (setq savehist-timer nil))) |
| 221 | 237 | ||
| 238 | ;; From XEmacs? | ||
| 239 | (defvar print-readably) | ||
| 240 | (defvar print-string-length) | ||
| 241 | |||
| 222 | (defun savehist-save (&optional auto-save) | 242 | (defun savehist-save (&optional auto-save) |
| 223 | "Save the values of minibuffer history variables. | 243 | "Save the values of minibuffer history variables. |
| 224 | Unbound symbols referenced in `savehist-additional-variables' are ignored. | 244 | Unbound symbols referenced in `savehist-additional-variables' are ignored. |
| @@ -235,7 +255,9 @@ If AUTO-SAVE is non-nil, compare the saved contents to the one last saved, | |||
| 235 | savehist-coding-system)) | 255 | savehist-coding-system)) |
| 236 | (run-hooks 'savehist-save-hook) | 256 | (run-hooks 'savehist-save-hook) |
| 237 | (let ((print-length nil) | 257 | (let ((print-length nil) |
| 258 | (print-string-length nil) | ||
| 238 | (print-level nil) | 259 | (print-level nil) |
| 260 | (print-readably t) | ||
| 239 | (print-quoted t)) | 261 | (print-quoted t)) |
| 240 | ;; Save the minibuffer histories, along with the value of | 262 | ;; Save the minibuffer histories, along with the value of |
| 241 | ;; savehist-minibuffer-history-variables itself. | 263 | ;; savehist-minibuffer-history-variables itself. |
| @@ -247,7 +269,7 @@ If AUTO-SAVE is non-nil, compare the saved contents to the one last saved, | |||
| 247 | (dolist (symbol savehist-minibuffer-history-variables) | 269 | (dolist (symbol savehist-minibuffer-history-variables) |
| 248 | (when (and (boundp symbol) | 270 | (when (and (boundp symbol) |
| 249 | (not (memq symbol savehist-ignored-variables))) | 271 | (not (memq symbol savehist-ignored-variables))) |
| 250 | (let ((value (symbol-value symbol)) | 272 | (let ((value (savehist-trim-history (symbol-value symbol))) |
| 251 | excess-space) | 273 | excess-space) |
| 252 | (when value ; Don't save empty histories. | 274 | (when value ; Don't save empty histories. |
| 253 | (insert "(setq ") | 275 | (insert "(setq ") |
| @@ -312,7 +334,17 @@ Does nothing if Savehist mode is off." | |||
| 312 | (when savehist-mode | 334 | (when savehist-mode |
| 313 | (savehist-save t))) | 335 | (savehist-save t))) |
| 314 | 336 | ||
| 315 | (define-obsolete-function-alias 'savehist-trim-history #'identity "27.1") | 337 | (defun savehist-trim-history (value) |
| 338 | "Retain only the first `history-length' items in VALUE. | ||
| 339 | Only used under XEmacs, which doesn't (yet) implement automatic | ||
| 340 | trimming of history lists to `history-length' items." | ||
| 341 | (if (and (featurep 'xemacs) | ||
| 342 | (natnump history-length) | ||
| 343 | (> (length value) history-length)) | ||
| 344 | ;; Equivalent to `(subseq value 0 history-length)', but doesn't | ||
| 345 | ;; need cl-extra at run-time. | ||
| 346 | (loop repeat history-length collect (pop value)) | ||
| 347 | value)) | ||
| 316 | 348 | ||
| 317 | (defun savehist-printable (value) | 349 | (defun savehist-printable (value) |
| 318 | "Return non-nil if VALUE is printable." | 350 | "Return non-nil if VALUE is printable." |
| @@ -327,18 +359,21 @@ Does nothing if Savehist mode is off." | |||
| 327 | ;; For others, check explicitly. | 359 | ;; For others, check explicitly. |
| 328 | (with-temp-buffer | 360 | (with-temp-buffer |
| 329 | (condition-case nil | 361 | (condition-case nil |
| 330 | (let ((print-level nil)) | 362 | (let ((print-readably t) (print-level nil)) |
| 331 | ;; Print the value into a buffer... | 363 | ;; Print the value into a buffer... |
| 332 | (prin1 value (current-buffer)) | 364 | (prin1 value (current-buffer)) |
| 333 | ;; ...and attempt to read it. | 365 | ;; ...and attempt to read it. |
| 334 | (read (point-min-marker)) | 366 | (read (point-min-marker)) |
| 335 | ;; The attempt worked: the object is printable. | 367 | ;; The attempt worked: the object is printable. |
| 336 | t) | 368 | t) |
| 337 | ;; The attempt failed: the object is not printable. | 369 | ;; The attempt failed: the object is not printable. |
| 338 | (error nil)))))) | 370 | (error nil)))))) |
| 339 | 371 | ||
| 340 | (defun savehist-minibuffer-hook () | 372 | (defun savehist-minibuffer-hook () |
| 341 | (unless (memq minibuffer-history-variable savehist-ignored-variables) | 373 | (unless (or (eq minibuffer-history-variable t) |
| 374 | ;; XEmacs sets minibuffer-history-variable to t to mean "no | ||
| 375 | ;; history is being recorded". | ||
| 376 | (memq minibuffer-history-variable savehist-ignored-variables)) | ||
| 342 | (add-to-list 'savehist-minibuffer-history-variables | 377 | (add-to-list 'savehist-minibuffer-history-variables |
| 343 | minibuffer-history-variable))) | 378 | minibuffer-history-variable))) |
| 344 | 379 | ||