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