diff options
-rw-r--r-- | README.org | 2 | ||||
-rw-r--r-- | lisp/mastodon-profile.el | 19 | ||||
-rw-r--r-- | lisp/mastodon-toot.el | 52 | ||||
-rw-r--r-- | lisp/mastodon.el | 2 |
4 files changed, 31 insertions, 44 deletions
@@ -421,7 +421,7 @@ to your translator function as its text argument. Here's what Hard dependencies (should all install with =mastodon.el=): - =request= (for uploading attachments), [[https://github.com/tkf/emacs-request][emacs-request]] -- +=persist= for storing some settings across sessions+ (we now use =multisession.el= for this) +- =persist= for storing some settings across sessions Optional dependencies (install yourself, =mastodon.el= can use them): - =emojify= to use custom emoji (else we use builtin =emoji.el=) diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index cd1978f..de16b7d 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -35,6 +35,7 @@ ;;; Code: (require 'seq) (require 'cl-lib) +(require 'persist) (require 'parse-time) (require 'mastodon-http) (eval-when-compile @@ -124,8 +125,8 @@ It contains details of the current user's account.") map) "Keymap for `mastodon-profile-update-mode'.") -(define-multisession-variable mastodon-profile-account-settings nil - "An alist of account settings saved from the server. +(persist-defvar mastodon-profile-account-settings nil + "An alist of account settings saved from the server. Other clients can change these settings on the server at any time, so this list is not the canonical source for settings. It is updated on entering mastodon mode and on toggle any setting it @@ -364,16 +365,13 @@ SOURCE means that the preference is in the `source' part of the account JSON." (defun mastodon-profile--get-pref (pref) "Return PREF from `mastodon-profile-account-settings'." - (plist-get (multisession-value mastodon-profile-account-settings) - pref)) + (plist-get mastodon-profile-account-settings pref)) (defun mastodon-profile--update-preference-plist (pref val) "Set local account preference plist preference PREF to VAL. This is done after changing the setting on the server." - (setf (multisession-value mastodon-profile-account-settings) - (plist-put - (multisession-value mastodon-profile-account-settings) - pref val))) + (setq mastodon-profile-account-settings + (plist-put mastodon-profile-account-settings pref val))) ;; used in toot.el (defun mastodon-profile--fetch-server-account-settings-maybe () @@ -386,8 +384,7 @@ Only do so if `mastodon-profile-account-settings' is nil." Store the values in `mastodon-profile-account-settings'. Run in `mastodon-mode-hook'. If NO-FORCE, only fetch if `mastodon-profile-account-settings' is nil." - (unless (and no-force - (multisession-value mastodon-profile-account-settings)) + (unless (and no-force mastodon-profile-account-settings) (let ((keys '(locked discoverable display_name bot)) (source-keys '(privacy sensitive language))) (mapc (lambda (k) @@ -405,7 +402,7 @@ If NO-FORCE, only fetch if `mastodon-profile-account-settings' is nil." ;; TODO: remove now redundant vars, replace with fetchers from the plist (setq mastodon-toot--visibility (mastodon-profile--get-pref 'privacy) mastodon-toot--content-nsfw (mastodon-profile--get-pref 'sensitive)) - (multisession-value mastodon-profile-account-settings)))) + mastodon-profile-account-settings))) (defun mastodon-profile--account-locked-toggle () "Toggle the locked status of your account. diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index f0895db..ae88d68 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -40,6 +40,7 @@ (defvar emojify-user-emojis) (require 'cl-lib) +(require 'persist) (require 'mastodon-iso) (require 'facemenu) (require 'text-property-search) @@ -223,8 +224,8 @@ Takes its form from `window-configuration-to-register'.") (defvar mastodon-toot-current-toot-text nil "The text of the toot being composed.") -(define-multisession-variable mastodon-toot-draft-toots-list nil - "A list of toots that have been saved as drafts. +(persist-defvar mastodon-toot-draft-toots-list nil + "A list of toots that have been saved as drafts. For the moment we just put all composed toots in here, as we want to also capture toots that are \"sent\" but that don't successfully send.") @@ -715,10 +716,8 @@ CANCEL means the toot was not sent, so we save the toot text as a draft." (let ((prev-window-config mastodon-toot-previous-window-config)) (unless (eq mastodon-toot-current-toot-text nil) (when cancel - (setf (multisession-value mastodon-toot-draft-toots-list) - (cl-pushnew mastodon-toot-current-toot-text - (multisession-value mastodon-toot-draft-toots-list) - :test 'equal)))) + (cl-pushnew mastodon-toot-current-toot-text + mastodon-toot-draft-toots-list :test 'equal))) ;; prevent some weird bug when cancelling a non-empty toot: (delete #'mastodon-toot--save-toot-text after-change-functions) (quit-window 'kill) @@ -739,10 +738,8 @@ Pushes `mastodon-toot-current-toot-text' to `mastodon-toot-draft-toots-list'." (interactive) (unless (eq mastodon-toot-current-toot-text nil) - (setf (multisession-value mastodon-toot-draft-toots-list) - (cl-pushnew mastodon-toot-current-toot-text - (multisession-value mastodon-toot-draft-toots-list) - :test 'equal)) + (cl-pushnew mastodon-toot-current-toot-text + mastodon-toot-draft-toots-list :test 'equal) (message "Draft saved!"))) (defun mastodon-toot--empty-p (&optional text-only) @@ -1828,18 +1825,16 @@ Added to `after-change-functions' in new toot buffers." (defun mastodon-toot--open-draft-toot () "Prompt for a draft and compose a toot with it." (interactive) - (if (multisession-value mastodon-toot-draft-toots-list) - (let ((text (completing-read - "Select draft toot: " - (multisession-value mastodon-toot-draft-toots-list) - nil t))) + (if mastodon-toot-draft-toots-list + (let ((text (completing-read "Select draft toot: " + mastodon-toot-draft-toots-list + nil t))) (if (not (mastodon-toot--compose-buffer-p)) (mastodon-toot--compose-buffer nil nil nil text) (when (and (not (mastodon-toot--empty-p :text-only)) (y-or-n-p "Replace current text with draft?")) - (setf (multisession-value mastodon-toot-draft-toots-list) - (cl-pushnew mastodon-toot-current-toot-text - (multisession-value mastodon-toot-draft-toots-list))) + (cl-pushnew mastodon-toot-current-toot-text + mastodon-toot-draft-toots-list) (goto-char (cdr (mastodon-tl--find-property-range 'toot-post-header (point-min)))) @@ -1854,22 +1849,19 @@ Added to `after-change-functions' in new toot buffers." (defun mastodon-toot--delete-draft-toot () "Prompt for a draft toot and delete it." (interactive) - (if (not (multisession-value mastodon-toot-draft-toots-list)) + (if (not mastodon-toot-draft-toots-list) (user-error "No drafts to delete") - (let ((draft (completing-read - "Select draft to delete: " - (multisession-value mastodon-toot-draft-toots-list) - nil t))) - (setf (multisession-value mastodon-toot-draft-toots-list) - (cl-delete draft - (multisession-value mastodon-toot-draft-toots-list) - :test #'equal)) + (let ((draft (completing-read "Select draft to delete: " + mastodon-toot-draft-toots-list + nil t))) + (setq mastodon-toot-draft-toots-list + (cl-delete draft mastodon-toot-draft-toots-list :test #'equal)) (message "Draft deleted!")))) (defun mastodon-toot--delete-all-drafts () "Delete all drafts." (interactive) - (setf (multisession-value mastodon-toot-draft-toots-list) nil) + (setq mastodon-toot-draft-toots-list nil) (message "All drafts deleted!")) @@ -1954,9 +1946,7 @@ EDIT means we are editing an existing toot, not composing a new one." (mastodon-toot-mode t) ;; set visibility: (setq mastodon-toot--visibility - (or (plist-get - (multisession-value mastodon-profile-account-settings) - 'privacy) + (or (plist-get mastodon-profile-account-settings 'privacy) ;; use toot visibility setting from the server: (mastodon-profile--get-source-value 'privacy) "public")) ; fallback diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 41b6fbe..82a2491 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -7,7 +7,7 @@ ;; Marty Hiatt <martianhiatus@riseup.net> ;; Maintainer: Marty Hiatt <martianhiatus@riseup.net> ;; Version: 1.0.24 -;; Package-Requires: ((emacs "27.1") (request "0.3.0")) +;; Package-Requires: ((emacs "27.1") (request "0.3.0") (persist "0.4")) ;; Homepage: https://codeberg.org/martianh/mastodon.el ;; This file is not part of GNU Emacs. |