diff options
author | Holger Dürer <me@hdurer.net> | 2017-05-16 21:09:58 +0100 |
---|---|---|
committer | Johnson Denen <johnson.denen@gmail.com> | 2017-05-18 10:21:21 -0400 |
commit | fe8e4386eacb358df0e16dc5bd37dde4f4d6d57c (patch) | |
tree | 2329c867ca4d8434e6e2200aae4f827e7f2a9165 /lisp | |
parent | 5f41086d3a03e8781aab77ab17f4d4f95263e07c (diff) |
Remove most byte-compile warnings.
We do this by
- moving vars into the files where they are (mostly) used
- "declaring" vars used elsewhere with the (defvar <var-name>) pattern,
- declaring functions defined in others functions rather than loading the file via require.
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/mastodon-auth.el | 5 | ||||
-rw-r--r-- | lisp/mastodon-client.el | 30 | ||||
-rw-r--r-- | lisp/mastodon-http.el | 11 | ||||
-rw-r--r-- | lisp/mastodon-inspect.el | 8 | ||||
-rw-r--r-- | lisp/mastodon-media.el | 25 | ||||
-rw-r--r-- | lisp/mastodon-tl.el | 45 | ||||
-rw-r--r-- | lisp/mastodon-toot.el | 32 | ||||
-rw-r--r-- | lisp/mastodon.el | 38 |
8 files changed, 107 insertions, 87 deletions
diff --git a/lisp/mastodon-auth.el b/lisp/mastodon-auth.el index 013487c..68c4d21 100644 --- a/lisp/mastodon-auth.el +++ b/lisp/mastodon-auth.el @@ -30,7 +30,10 @@ ;;; Code: (require 'plstore) -(require 'mastodon-client nil t) + +(declare-function mastodon-client "mastodon-client") +(declare-function mastodon-http--post "mastodon-http") +(defvar mastodon-instance-url) (defgroup mastodon-auth nil "Authenticate with Mastodon." diff --git a/lisp/mastodon-client.el b/lisp/mastodon-client.el index f8e8a5c..3a9a606 100644 --- a/lisp/mastodon-client.el +++ b/lisp/mastodon-client.el @@ -30,14 +30,16 @@ ;;; Code: (require 'plstore) -(require 'mastodon-http nil t) +(declare-function mastodon-http--api "mastodon-http") +(declare-function mastodon-http--post "mastodon-http") -(defgroup mastodon-client nil - "Register your client with Mastodon." - :prefix "mastodon-client-" - :group 'mastodon) -(defvar mastodon-client nil +(defcustom mastodon-client--token-file (concat user-emacs-directory "mastodon.plstore") + "File path where Mastodon access tokens are stored." + :group 'mastodon + :type 'file) + +(defvar mastodon-client--client-details nil "Client id and secret.") (defun mastodon-client--register () @@ -62,11 +64,11 @@ (json-read-from-string json-string)))) (defun mastodon-client--token-file () - "Return `mastodon-token-file'." - mastodon-token-file) + "Return `mastodon-client--token-file'." + mastodon-client--token-file) (defun mastodon-client--store () - "Store client_id and client_secret in `mastodon-token-file'. + "Store client_id and client_secret in `mastodon-client--token-file'. Make `mastodon-client--fetch' call to determine client values." (let ((plstore (plstore-open (mastodon-client--token-file))) @@ -77,19 +79,19 @@ Make `mastodon-client--fetch' call to determine client values." client)) (defun mastodon-client--read () - "Retrieve client_id and client_secret from `mastodon-token-file'." + "Retrieve client_id and client_secret from `mastodon-client--token-file'." (let* ((plstore (plstore-open (mastodon-client--token-file))) (mastodon (plstore-get plstore "mastodon"))) (when mastodon (delete "mastodon" mastodon)))) (defun mastodon-client () - "Return variable `mastodon-client' plist. + "Return variable `mastodon-client--client-details' plist. -Read plist from `mastodon-token-file' if variable is nil. +Read plist from `mastodon-client--token-file' if variable is nil. Fetch and store plist if `mastodon-client--read' returns nil." - (or mastodon-client - (setq mastodon-client + (or mastodon-client--client-details + (setq mastodon-client--client-details (or (mastodon-client--read) (mastodon-client--store))))) diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el index dbbad4f..9f178c4 100644 --- a/lisp/mastodon-http.el +++ b/lisp/mastodon-http.el @@ -30,15 +30,16 @@ ;;; Code: (require 'json) +(defvar mastodon-instance-url) +(defvar mastodon-auth--token) +(declare-function mastodon-auth--access-token "mastodon-auth") -(defgroup mastodon-http nil - "HTTP requests and responses for Mastodon." - :prefix "mastodon-http-" - :group 'mastodon) +(defvar mastodon-http--api-version "v1") (defun mastodon-http--api (endpoint) "Return Mastondon API URL for ENDPOINT." - (concat mastodon-instance-url "/api/" mastodon--api-version "/" endpoint)) + (concat mastodon-instance-url "/api/" + mastodon-http--api-version "/" endpoint)) (defun mastodon-http--response () "Capture response buffer content as string." diff --git a/lisp/mastodon-inspect.el b/lisp/mastodon-inspect.el index c12273e..f5fcd81 100644 --- a/lisp/mastodon-inspect.el +++ b/lisp/mastodon-inspect.el @@ -28,8 +28,12 @@ ;; Some tools to help inspect / debug mastodon.el ;;; Code: - -(require 'mastodon-tl nil t) +(declare-function mastodon-http--api "mastodon-http") +(declare-function mastodon-http--get-json "mastodon-http") +(declare-function mastodon-media--inline-images "mastodon-media") +(declare-function mastodon-mode "mastodon") +(declare-function mastodon-tl--property "mastodon-tl") +(declare-function mastodon-tl--toot "mastodon-tl") (defgroup mastodon-inspect nil "Tools to help inspect toots." diff --git a/lisp/mastodon-media.el b/lisp/mastodon-media.el index b3565d0..671f159 100644 --- a/lisp/mastodon-media.el +++ b/lisp/mastodon-media.el @@ -32,16 +32,20 @@ ;; required by the server and client. ;;; Code: -(require 'mastodon-http nil t) - (defgroup mastodon-media nil "Inline Mastadon media." :prefix "mastodon-media-" :group 'mastodon) -(defvar mastodon-media-show-avatars-p - (image-type-available-p 'imagemagick) - "A boolean value stating whether to show avatars in timelines.") +(defcustom mastodon-media--avatar-height 30 + "Height of the user avatar images (if shown)." + :group 'mastodon-media + :type 'integer) + +(defcustom mastodon-media--preview-max-height 250 + "Max height of any media attachment preview to be shown." + :group 'mastodon-media + :type 'integer) (defvar mastodon-media--generic-avatar-data (base64-decode-string @@ -121,14 +125,13 @@ BAIQCEAgAIEABAIsJVH58WqHw8FIgjUIQCAACAQgEIBAAAIBCAQgEIBAAAIBCAQgEAAEAhAIQCBA fKRJkmVZjAQwh78A6vCRWJE8K+8AAAAASUVORK5CYII=") "The PNG data for a generic 200x200 'broken image' view") -(defun mastodon-media--process-image-response (status-plist marker image-options region-length image-url) +(defun mastodon-media--process-image-response (status-plist marker image-options region-length) "Callback function processing the url retrieve response for URL. STATUS-PLIST is the usual plist of status events as per `url-retrieve'. IMAGE-OPTIONS are the precomputed options to apply to the image. MARKER is the marker to where the response should be visible. REGION-LENGTH is the length of the region that should be replaced with the image. -IMAGE-URL is the URL that was retrieved. " (let ((url-buffer (current-buffer)) (is-error-response-p (eq :error (car status-plist)))) @@ -164,12 +167,12 @@ MEDIA-TYPE is a symbol and either 'avatar or 'media-link." (let ((image-options (when (image-type-available-p 'imagemagick) (cond ((eq media-type 'avatar) - `(:height ,mastodon-avatar-height)) + `(:height ,mastodon-media--avatar-height)) ((eq media-type 'media-link) - `(:max-height ,mastodon-preview-max-height)))))) + `(:max-height ,mastodon-media--preview-max-height)))))) (url-retrieve url #'mastodon-media--process-image-response - (list (copy-marker start) image-options region-length url)))) + (list (copy-marker start) image-options region-length)))) (defun mastodon-media--select-next-media-line () "Find coordinates of the next media to load. @@ -225,7 +228,7 @@ not been returned." ;; This is what a user will see on a non-graphical display ;; where not showing an avatar at all is preferable. (let ((image-options (when (image-type-available-p 'imagemagick) - `(:height ,mastodon-avatar-height)))) + `(:height ,mastodon-media--avatar-height)))) (concat (propertize " " 'media-url avatar-url diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 5b06119..edefae9 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -29,16 +29,31 @@ ;;; Code: -(require 'mastodon-http) -(require 'mastodon-toot) -(require 'mastodon-media) +(require 'shr) +(require 'thingatpt) ;; for word-at-point (require 'time-date) +(declare-function mastodon-http--api "mastodon-http") +(declare-function mastodon-http--get-json "mastodon-http") +(declare-function mastodon-media--get-avatar-rendering "mastodon-media") +(declare-function mastodon-media--get-media-link-rendering "mastodon-media") +(declare-function mastodon-media--inline-images "mastodon-media") +(declare-function mastodon-mode "mastodon") +(defvar mastodon-toot-timestamp-format) + (defgroup mastodon-tl nil "Timelines in Mastodon." :prefix "mastodon-tl-" :group 'mastodon) +(defvar mastodon-tl--buffer-spec nil + "A unique identifier and functions for each Mastodon buffer.") + +(defvar mastodon-tl--show-avatars-p + (image-type-available-p 'imagemagick) + "A boolean value stating whether to show avatars in timelines.") + + (defun mastodon-tl--get-federated-timeline () "Opens federated timeline." (interactive) @@ -106,7 +121,7 @@ Optionally start from POS." (name (cdr (assoc 'display_name account))) (avatar-url (cdr (assoc 'avatar account)))) (concat - (when mastodon-media-show-avatars-p + (when mastodon-tl--show-avatars-p (mastodon-media--get-avatar-rendering avatar-url)) (propertize name 'face 'mastodon-display-name-face) (propertize (concat " (@" @@ -218,28 +233,28 @@ also render the html" (defun mastodon-tl--timeline (toots) "Display each toot in TOOTS." - (mapcar 'mastodon-tl--toot toots) + (mapc 'mastodon-tl--toot toots) (replace-regexp "\n\n\n | " "\n | " nil (point-min) (point-max)) (mastodon-media--inline-images)) (defun mastodon-tl--get-update-function (&optional buffer) - "Get the UPDATE-FUNCTION stored in `mastodon-buffer-spec'" + "Get the UPDATE-FUNCTION stored in `mastodon-tl--buffer-spec'" (mastodon-tl--get-buffer-property 'update-function buffer)) (defun mastodon-tl--get-endpoint (&optional buffer) - "Get the ENDPOINT stored in `mastodon-buffer-spec'" + "Get the ENDPOINT stored in `mastodon-tl--buffer-spec'" (mastodon-tl--get-buffer-property 'endpoint buffer)) (defun mastodon-tl--buffer-name (&optional buffer) - "Get the BUFFER-NAME stored in `mastodon-buffer-spec'" + "Get the BUFFER-NAME stored in `mastodon-tl--buffer-spec'" (mastodon-tl--get-buffer-property 'buffer-name buffer )) (defun mastodon-tl--get-buffer-property (property &optional buffer) - "Get `MASTODON-BUFFER-SPEC' in BUFFER or `CURRENT-BUFFER'" + "Get `MASTODON-TL--BUFFER-SPEC' in BUFFER or `CURRENT-BUFFER'" (with-current-buffer (or buffer (current-buffer)) - (if (plist-get mastodon-buffer-spec property) - (plist-get mastodon-buffer-spec property) - (error "mastodon-buffer-spec is not defined for buffer %s" + (if (plist-get mastodon-tl--buffer-spec property) + (plist-get mastodon-tl--buffer-spec property) + (error "mastodon-tl--buffer-spec is not defined for buffer %s" (or buffer (current-buffer)))))) (defun mastodon-tl--more-json (endpoint id) @@ -303,7 +318,7 @@ Move forward (down) the timeline unless BACKWARD is non-nil." (cdr (assoc 'descendants context))))) (mastodon-mode))) -(defun mastodon-tl--more (&optional buffer) +(defun mastodon-tl--more () "Append older toots to timeline." (interactive) (let* ((point-before (point)) @@ -342,8 +357,8 @@ UPDATE-FUNCTION is used to recieve more toots." (funcall update-function json)) (mastodon-mode) (with-current-buffer buffer - (make-local-variable 'mastodon-buffer-spec) - (setq mastodon-buffer-spec + (make-local-variable 'mastodon-tl--buffer-spec) + (setq mastodon-tl--buffer-spec `(buffer-name ,buffer-name endpoint ,endpoint update-function ,update-function))) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index fc31a5b..ffe6454 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -29,16 +29,26 @@ ;;; Code: -(require 'mastodon-auth nil t) - -(defgroup mastodon-toot nil - "Capture Mastodon toots." - :prefix "mastodon-toot-" - :group 'mastodon) - (defvar mastodon-toot--reply-to-id nil) (defvar mastodon-toot--content-warning nil) +(declare-function mastodon-http--api "mastodon-http") +(declare-function mastodon-http--post "mastodon-http") +(declare-function mastodon-http--triage "mastodon-http") +(declare-function mastodon-tl--field "mastodon-tl") +(declare-function mastodon-tl--goto-next-toot "mastodon-tl") +(declare-function mastodon-tl--property "mastodon-tl") +(declare-function mastodon-toot "mastodon") + +(defvar mastodon-toot-mode-map + (let ((map (make-sparse-keymap))) + (define-key map (kbd "C-c C-c") #'mastodon-toot--send) + (define-key map (kbd "C-c C-k") #'mastodon-toot--cancel) + (define-key map (kbd "C-c C-w") #'mastodon-toot--toggle-warning) + map) + "Keymap for `mastodon-toot'.") + + (defun mastodon-toot--action-success (marker &optional rm) "Insert MARKER with 'success face in byline. @@ -211,14 +221,6 @@ If REPLY-TO-ID is provided, set the MASTODON-TOOT--REPLY-TO-ID var." (mastodon-toot--setup-as-reply reply-to-user reply-to-id)) (mastodon-toot-mode t))) -(defvar mastodon-toot-mode-map - (let ((map (make-sparse-keymap))) - (define-key map (kbd "C-c C-c") #'mastodon-toot--send) - (define-key map (kbd "C-c C-k") #'mastodon-toot--cancel) - (define-key map (kbd "C-c C-w") #'mastodon-toot--toggle-warning) - map) - "Keymap for `mastodon-toot'.") - (define-minor-mode mastodon-toot-mode "Minor mode to capture Mastodon toots." :group 'mastodon-toot diff --git a/lisp/mastodon.el b/lisp/mastodon.el index a0dd732..9f7257e 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -30,8 +30,20 @@ ;; it is a labor of love. ;;; Code: - -(require 'mastodon-auth nil t) +(declare-function discover-add-context-menu "discover") +(declare-function emojify-mode "emojify") +(declare-function mastodon-tl--get-federated-timeline "mastodon-tl") +(declare-function mastodon-tl--get-home-timeline "mastodon-tl") +(declare-function mastodon-tl--get-local-timeline "mastodon-tl") +(declare-function mastodon-tl--get-tag-timeline "mastodon-tl") +(declare-function mastodon-tl--goto-next-toot "mastodon-tl") +(declare-function mastodon-tl--goto-prev-toot "mastodon-tl") +(declare-function mastodon-tl--thread "mastodon-tl") +(declare-function mastodon-tl--update "mastodon-tl") +(declare-function mastodon-toot--compose-buffer "mastodon-toot") +(declare-function mastodon-toot--reply "mastodon-toot") +(declare-function mastodon-toot--toggle-boost "mastodon-toot") +(declare-function mastodon-toot--toggle-favourite "mastodon-toot") (defgroup mastodon nil "Interface with Mastodon." @@ -43,11 +55,6 @@ :group 'mastodon :type 'string) -(defcustom mastodon-token-file (concat user-emacs-directory "mastodon.plstore") - "File path where Mastodon access tokens are stored." - :group 'mastodon - :type 'file) - (defcustom mastodon-toot-timestamp-format "%F %T" "Format to use for timestamps. @@ -57,25 +64,10 @@ Use. e.g. \"%c\" for your locale's date and time format." :group 'mastodon :type 'string) -(defcustom mastodon-avatar-height 30 - "Height of the user avatar images (if shown)." - :group 'mastodon - :type 'integer) - -(defcustom mastodon-preview-max-height 250 - "Max height of any media attachment preview to be shown." - :group 'mastodon - :type 'integer) - (defvar mastodon-mode-map (make-sparse-keymap) "Keymap for `mastodon-mode'.") -(defvar mastodon--api-version "v1") - -(defvar mastodon-buffer-spec nil - "A unique identifier and functions for each Mastodon buffer.") - (defcustom mastodon-mode-hook nil "Hook run when entering Mastodon mode." :type 'hook @@ -106,7 +98,6 @@ Use. e.g. \"%c\" for your locale's date and time format." (defun mastodon () "Connect Mastodon client to `mastodon-instance-url' instance." (interactive) - (require 'mastodon-tl nil t) (mastodon-tl--get-home-timeline)) ;;;###autoload @@ -116,7 +107,6 @@ Use. e.g. \"%c\" for your locale's date and time format." If USER is non-nil, insert after @ symbol to begin new toot. If REPLY-TO-ID is non-nil, attach new toot to a conversation." (interactive) - (require 'mastodon-toot nil t) (mastodon-toot--compose-buffer user reply-to-id)) ;;;###autoload |