[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/preview-tailor f54e2b333a 14/16: save monitor-specific
From: |
ELPA Syncer |
Subject: |
[elpa] externals/preview-tailor f54e2b333a 14/16: save monitor-specific settings in dotfile rather than defcustom |
Date: |
Thu, 6 Jun 2024 04:00:10 -0400 (EDT) |
branch: externals/preview-tailor
commit f54e2b333a2e075cd8ef0e0bfc0fb8f50969952b
Author: Paul Nelson <ultrono@gmail.com>
Commit: Paul Nelson <ultrono@gmail.com>
save monitor-specific settings in dotfile rather than defcustom
---
README.org | 38 ++++++--------------------------------
preview-tailor.el | 28 +++++++++++++++++++---------
2 files changed, 25 insertions(+), 41 deletions(-)
diff --git a/README.org b/README.org
index 2900e42806..52066a0ff1 100644
--- a/README.org
+++ b/README.org
@@ -26,38 +26,12 @@ This package calculates the preview scale by multiplying
together four factors:
To adjust the multiplier for a given monitor, use =M-x
preview-tailor-set-multiplier=. This adjusts the customization variable
=preview-tailor-multipliers=, which is an association list mapping lists of
monitor attributes to numbers. The multiplier is calculated by finding the
first entry in the list all of whose attributes match the current ones.
* Saving your settings
-If you use the built-in customization feature, then you can save your
multipliers for future sessions using =M-x preview-tailor-save=. To make this
automatic, you could add =(add-hook 'kill-emacs-hook #'preview-tailor-save)= to
your init file.
+The package stores your monitor-specific settings in the dotfile
".preview-tailor" inside your user-emacs-directory. This allows you to keep
your settings separate from your init file, making it easier to sync your Emacs
configuration across different computers.
+
+To save your multipliers for future sessions, use =M-x preview-tailor-save=.
The package will automatically load the settings from the dotfile when
initialized. To make saving automatic, you can add the following to your init
file:
-If you've disabled the built-in customization feature, then you can save the
multipliers in your init file. Here's what I do:
#+begin_src elisp
-(use-package preview-tailor
- :elpaca (:host github :repo "ultronozm/preview-tailor.el"
- :depth nil)
- :after latex
- :config
- (preview-tailor-init)
- :custom
- (preview-tailor-multipliers
- '((((geometry 0 -2520 1920 1080)
- (workarea 0 -2520 1920 1080)
- (mm-size 1434 806)
- (source . "NS"))
- . 4)
- (((geometry -832 -1440 2560 1440)
- (workarea -832 -1440 2560 1440)
- (mm-size 602 338)
- (source . "NS"))
- . 1.2)
- (((geometry 0 0 1728 1117)
- (workarea 0 32 1728 1085)
- (mm-size 344 222)
- (source . "NS"))
- . 1.2)
- (((geometry 0 -1440 2560 1440)
- (workarea 0 -1440 2560 1440)
- (mm-size 602 338)
- (source . "NS"))
- . 1.2)
- (nil . 1.2))))
+(add-hook 'kill-emacs-hook #'preview-tailor-save)
#+end_src
-When I want to modify this, I use =preview-tailor-set-multiplier= and then
copy the new value of =preview-tailor-multipliers= into the above.
+
+If you prefer to edit the dotfile directly, the function =preview-tailor-load=
might be come in handy -- it loads the settings from the dotfile into the
variable =preview-tailor-multipliers=.
diff --git a/preview-tailor.el b/preview-tailor.el
index ee1efb6d9a..4a4321a058 100644
--- a/preview-tailor.el
+++ b/preview-tailor.el
@@ -3,7 +3,7 @@
;; Copyright (C) 2024 Paul D. Nelson
;; Author: Paul D. Nelson <nelson.paul.david@gmail.com>
-;; Version: 0.0
+;; Version: 0.1
;; URL: https://github.com/ultronozm/preview-tailor.el
;; Package-Requires: ((emacs "29.1") (auctex))
;; Keywords: tex, multimedia
@@ -32,17 +32,14 @@
(require 'latex)
(require 'preview)
-(defcustom preview-tailor-multipliers
+(defvar preview-tailor-multipliers
'((() . 1.0))
"Alist mapping lists of monitor attributes to multipliers.
Each monitor is described by a list of its attributes, which
should be a subset of those returned by
`frame-monitor-attributes'. The empty list of attributes ()
-matches against everything, hence functions as a default."
- :group 'AUCTeX
- :type '(alist :key-type (repeat (sexp :tag "Monitor Attribute"))
- :value-type (number :tag "Preview Scale")))
+matches against everything, hence functions as a default.")
(defun preview-tailor--get-match (attr-list)
"Return preview scale corresponding to attribute list ATTR-LIST.
@@ -62,7 +59,7 @@ nil if no match found."
(defcustom preview-tailor-additional-factor-function nil
"Function to calculate an additional factor for preview scale.
-This function should take no arguments and returns a number. The
+This function should take no arguments and returns a number. The
returned number is used as a multiplication factor in
`preview-tailor--calculate'. If nil, then the no additional
factor is used."
@@ -112,17 +109,30 @@ Use SCALE if provided, otherwise prompt for it."
(setcdr item scale)
(add-to-list 'preview-tailor-multipliers (cons attr scale)))))
+(defconst preview-tailor-storage-file
+ (expand-file-name ".preview-tailor" user-emacs-directory)
+ "File name where settings are stored.")
+
+(defun preview-tailor-load ()
+ "Load preview-tailor customization from a dotfile."
+ (when (file-exists-p preview-tailor-storage-file)
+ (with-temp-buffer
+ (insert-file-contents preview-tailor-storage-file)
+ (setq preview-tailor-multipliers (read (current-buffer))))))
+
;;;###autoload
(defun preview-tailor-init ()
"Initialize preview-tailor."
(interactive)
+ (preview-tailor-load)
(setq preview-scale-function #'preview-tailor--calculate))
;;;###autoload
(defun preview-tailor-save ()
- "Save preview-tailor customization."
+ "Save preview-tailor customization to a dotfile."
(interactive)
- (customize-save-variable 'preview-tailor-multipliers
preview-tailor-multipliers))
+ (with-temp-file preview-tailor-storage-file
+ (prin1 preview-tailor-multipliers (current-buffer))))
(provide 'preview-tailor)
;;; preview-tailor.el ends here
- [elpa] externals/preview-tailor 88246e0095 03/16: init, (continued)
- [elpa] externals/preview-tailor 88246e0095 03/16: init, ELPA Syncer, 2024/06/06
- [elpa] externals/preview-tailor 302b378c9e 13/16: Update preview-tailor.el, ELPA Syncer, 2024/06/06
- [elpa] externals/preview-tailor 4f27984034 12/16: remove auctex dependency, ELPA Syncer, 2024/06/06
- [elpa] externals/preview-tailor 1784736b3d 11/16: added buffer-local preview-tailor-local-multiplier, ELPA Syncer, 2024/06/06
- [elpa] externals/preview-tailor 5b32613df1 04/16: typo, ELPA Syncer, 2024/06/06
- [elpa] externals/preview-tailor 0b028a9d05 05/16: clarify, ELPA Syncer, 2024/06/06
- [elpa] externals/preview-tailor fc38cb576f 07/16: clarity, ELPA Syncer, 2024/06/06
- [elpa] externals/preview-tailor 2010b383b3 10/16: add preview-tailor-additional-factor-function, ELPA Syncer, 2024/06/06
- [elpa] externals/preview-tailor 8a1aab7498 15/16: tidy, ELPA Syncer, 2024/06/06
- [elpa] externals/preview-tailor 0904a48f72 16/16: some docs added, ELPA Syncer, 2024/06/06
- [elpa] externals/preview-tailor f54e2b333a 14/16: save monitor-specific settings in dotfile rather than defcustom,
ELPA Syncer <=
- [elpa] externals/preview-tailor d75cb788ae 06/16: typo, ELPA Syncer, 2024/06/06
- [elpa] externals/preview-tailor 6b7604e16d 08/16: preview-tailor-save, ELPA Syncer, 2024/06/06
- [elpa] externals/preview-tailor 3bf5c787c4 09/16: mention save hook option, ELPA Syncer, 2024/06/06