From df9a7194fc22d499d6fb45383fc98e6bb9b35dd6 Mon Sep 17 00:00:00 2001 From: Holger Dürer Date: Fri, 5 May 2017 22:02:56 +0100 Subject: Use lexical-binding in all files. We only support Emacs 24 and 25 so are free to use sane bindings by default. To keep the linter happy, we need to declare dependency on Emacs 24 in all files. --- lisp/mastodon-inspect.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lisp/mastodon-inspect.el') diff --git a/lisp/mastodon-inspect.el b/lisp/mastodon-inspect.el index 9ae5049..97d7660 100644 --- a/lisp/mastodon-inspect.el +++ b/lisp/mastodon-inspect.el @@ -1,4 +1,4 @@ -;;; mastodon-inspect.el --- Client for Mastodon +;;; mastodon-inspect.el --- Client for Mastodon -*- lexical-binding: t -*- ;; Copyright (C) 2017 Johnson Denen ;; Author: Johnson Denen -- cgit v1.2.3 From 23c233d2bb2cbc9139087b53d95cd3b23e05e336 Mon Sep 17 00:00:00 2001 From: Johnson Denen Date: Mon, 15 May 2017 09:28:14 -0400 Subject: Bump to v0.6.3 --- lisp/mastodon-auth.el | 2 +- lisp/mastodon-client.el | 2 +- lisp/mastodon-http.el | 2 +- lisp/mastodon-inspect.el | 2 +- lisp/mastodon-media.el | 2 +- lisp/mastodon-tl.el | 2 +- lisp/mastodon-toot.el | 2 +- lisp/mastodon.el | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) (limited to 'lisp/mastodon-inspect.el') diff --git a/lisp/mastodon-auth.el b/lisp/mastodon-auth.el index 093c5f1..013487c 100644 --- a/lisp/mastodon-auth.el +++ b/lisp/mastodon-auth.el @@ -2,7 +2,7 @@ ;; Copyright (C) 2017 Johnson Denen ;; Author: Johnson Denen -;; Version: 0.6.2 +;; Version: 0.6.3 ;; Homepage: https://github.com/jdenen/mastodon.el ;; Package-Requires: ((emacs "24.4")) diff --git a/lisp/mastodon-client.el b/lisp/mastodon-client.el index ebfb844..f8e8a5c 100644 --- a/lisp/mastodon-client.el +++ b/lisp/mastodon-client.el @@ -2,7 +2,7 @@ ;; Copyright (C) 2017 Johnson Denen ;; Author: Johnson Denen -;; Version: 0.6.2 +;; Version: 0.6.3 ;; Homepage: https://github.com/jdenen/mastodon.el ;; Package-Requires: ((emacs "24.4")) diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el index 48be898..dbbad4f 100644 --- a/lisp/mastodon-http.el +++ b/lisp/mastodon-http.el @@ -2,7 +2,7 @@ ;; Copyright (C) 2017 Johnson Denen ;; Author: Johnson Denen -;; Version: 0.6.2 +;; Version: 0.6.3 ;; Package-Requires: ((emacs "24.4")) ;; Homepage: https://github.com/jdenen/mastodon.el diff --git a/lisp/mastodon-inspect.el b/lisp/mastodon-inspect.el index 97d7660..c12273e 100644 --- a/lisp/mastodon-inspect.el +++ b/lisp/mastodon-inspect.el @@ -2,7 +2,7 @@ ;; Copyright (C) 2017 Johnson Denen ;; Author: Johnson Denen -;; Version: 0.6.2 +;; Version: 0.6.3 ;; Package-Requires: ((emacs "24.4")) ;; Homepage: https://github.com/jdenen/mastodon.el diff --git a/lisp/mastodon-media.el b/lisp/mastodon-media.el index 04293c5..b3565d0 100644 --- a/lisp/mastodon-media.el +++ b/lisp/mastodon-media.el @@ -2,7 +2,7 @@ ;; Copyright (C) 2017 Johnson Denen ;; Author: Johnson Denen -;; Version: 0.6.2 +;; Version: 0.6.3 ;; Homepage: https://github.com/jdenen/mastodon.el ;; Package-Requires: ((emacs "24.4")) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 5e09cf1..42cb252 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -2,7 +2,7 @@ ;; Copyright (C) 2017 Johnson Denen ;; Author: Johnson Denen -;; Version: 0.6.2 +;; Version: 0.6.3 ;; Homepage: https://github.com/jdenen/mastodon.el ;; Package-Requires: ((emacs "24.4")) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index ace7d70..fc31a5b 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -2,7 +2,7 @@ ;; Copyright (C) 2017 Johnson Denen ;; Author: Johnson Denen -;; Version: 0.6.2 +;; Version: 0.6.3 ;; Homepage: https://github.com/jdenen/mastodon.el ;; Package-Requires: ((emacs "24.4")) diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 2b8f1ea..b75c608 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -2,7 +2,7 @@ ;; Copyright (C) 2017 Johnson Denen ;; Author: Johnson Denen -;; Version: 0.6.2 +;; Version: 0.6.3 ;; Package-Requires: ((emacs "24.4")) ;; Homepage: https://github.com/jdenen/mastodon.el -- cgit v1.2.3 From fe8e4386eacb358df0e16dc5bd37dde4f4d6d57c Mon Sep 17 00:00:00 2001 From: Holger Dürer Date: Tue, 16 May 2017 21:09:58 +0100 Subject: 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 ) pattern, - declaring functions defined in others functions rather than loading the file via require. --- lisp/mastodon-auth.el | 5 ++++- lisp/mastodon-client.el | 30 +++++++++++++++-------------- lisp/mastodon-http.el | 11 ++++++----- lisp/mastodon-inspect.el | 8 ++++++-- lisp/mastodon-media.el | 25 +++++++++++++----------- lisp/mastodon-tl.el | 45 ++++++++++++++++++++++++++++--------------- lisp/mastodon-toot.el | 32 +++++++++++++++--------------- lisp/mastodon.el | 38 ++++++++++++++---------------------- test/mastodon-client-tests.el | 10 +++++----- test/mastodon-media-tests.el | 20 +++++++++---------- test/mastodon-tl-tests.el | 16 +++++++-------- 11 files changed, 130 insertions(+), 110 deletions(-) (limited to 'lisp/mastodon-inspect.el') 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 diff --git a/test/mastodon-client-tests.el b/test/mastodon-client-tests.el index e1f92f8..c339efa 100644 --- a/test/mastodon-client-tests.el +++ b/test/mastodon-client-tests.el @@ -54,22 +54,22 @@ (ert-deftest client-1 () "Should return `mastondon-client' if non-nil." - (let ((mastodon-client t)) + (let ((mastodon-client--client-details t)) (should (eq (mastodon-client) t)))) (ert-deftest client-2 () "Should read from `mastodon-token-file' if available." - (let ((mastodon-client nil)) + (let ((mastodon-client--client-details nil)) (with-mock (mock (mastodon-client--read) => '(:client_id "foo" :client_secret "bar")) (should (equal (mastodon-client) '(:client_id "foo" :client_secret "bar"))) - (should (equal mastodon-client '(:client_id "foo" :client_secret "bar")))))) + (should (equal mastodon-client--client-details '(:client_id "foo" :client_secret "bar")))))) (ert-deftest client-3 () "Should store client data in plstore if it can't be read." - (let ((mastodon-client nil)) + (let ((mastodon-client--client-details nil)) (with-mock (mock (mastodon-client--read)) (mock (mastodon-client--store) => '(:client_id "foo" :client_secret "baz")) (should (equal (mastodon-client) '(:client_id "foo" :client_secret "baz"))) - (should (equal mastodon-client '(:client_id "foo" :client_secret "baz")))))) + (should (equal mastodon-client--client-details '(:client_id "foo" :client_secret "baz")))))) diff --git a/test/mastodon-media-tests.el b/test/mastodon-media-tests.el index 9cd06b7..4bb89c7 100644 --- a/test/mastodon-media-tests.el +++ b/test/mastodon-media-tests.el @@ -6,7 +6,7 @@ (mock (image-type-available-p 'imagemagick) => t) (mock (create-image * 'imagemagick t :height 123) => :mock-image) - (let* ((mastodon-avatar-height 123) + (let* ((mastodon-media--avatar-height 123) (result (mastodon-media--get-avatar-rendering "http://example.org/img.png")) (result-no-properties (substring-no-properties result)) (properties (text-properties-at 0 result))) @@ -21,7 +21,7 @@ (with-mock (mock (create-image * nil t) => :mock-image) - (let* ((mastodon-preview-max-height 123) + (let* ((mastodon-media--preview-max-height 123) (result (mastodon-media--get-media-link-rendering "http://example.org/img.png")) (result-no-properties (substring-no-properties result)) (properties (text-properties-at 0 result))) @@ -34,7 +34,7 @@ (ert-deftest mastodon-media:load-image-from-url:avatar-with-imagemagic () "Should make the right call to url-retrieve." (let ((url "http://example.org/image.png") - (mastodon-avatar-height 123)) + (mastodon-media--avatar-height 123)) (with-mock (mock (image-type-available-p 'imagemagick) => t) (mock (create-image * 'imagemagick t :height 123) => '(image foo)) @@ -42,7 +42,7 @@ (mock (url-retrieve url #'mastodon-media--process-image-response - '(:my-marker (:height 123) 1 "http://example.org/image.png")) + '(:my-marker (:height 123) 1)) => :called-as-expected) (with-temp-buffer @@ -62,7 +62,7 @@ (mock (url-retrieve url #'mastodon-media--process-image-response - '(:my-marker () 1 "http://example.org/image.png")) + '(:my-marker () 1)) => :called-as-expected) (with-temp-buffer @@ -82,13 +82,13 @@ (mock (url-retrieve "http://example.org/image.png" #'mastodon-media--process-image-response - '(:my-marker (:max-height 321) 5 "http://example.org/image.png")) + '(:my-marker (:max-height 321) 5)) => :called-as-expected) (with-temp-buffer (insert (concat "Start:" (mastodon-media--get-media-link-rendering url) ":rest")) - (let ((mastodon-preview-max-height 321)) + (let ((mastodon-media--preview-max-height 321)) (should (eq :called-as-expected (mastodon-media--load-image-from-url url 'media-link 7 5)))))))) (ert-deftest mastodon-media:load-image-from-url:media-link-without-imagemagic () @@ -101,14 +101,14 @@ (mock (url-retrieve "http://example.org/image.png" #'mastodon-media--process-image-response - '(:my-marker () 5 "http://example.org/image.png")) + '(:my-marker () 5)) => :called-as-expected) (with-temp-buffer (insert (concat "Start:" (mastodon-media--get-avatar-rendering url) ":rest")) - (let ((mastodon-preview-max-height 321)) + (let ((mastodon-media--preview-max-height 321)) (should (eq :called-as-expected (mastodon-media--load-image-from-url url 'media-link 7 5)))))))) (ert-deftest mastodon-media:process-image-response () @@ -134,7 +134,7 @@ (mock (create-image "fake\nimage\ndata" 'imagemagick t ':image :option) => :fake-image) - (mastodon-media--process-image-response () used-marker '(:image :option) 1 "the-url") + (mastodon-media--process-image-response () used-marker '(:image :option) 1) ;; the used marker has been unset: (should (null (marker-position used-marker))) diff --git a/test/mastodon-tl-tests.el b/test/mastodon-tl-tests.el index caea476..8c706f5 100644 --- a/test/mastodon-tl-tests.el +++ b/test/mastodon-tl-tests.el @@ -105,7 +105,7 @@ (ert-deftest mastodon-tl--byline-regular () "Should format the regular toot correctly." - (let ((mastodon-media-show-avatars-p nil) + (let ((mastodon-tl--show-avatars-p nil) (timestamp (cdr (assoc 'created_at mastodon-tl-test-base-toot)))) (with-mock (mock (date-to-time timestamp) => '(22782 21551)) @@ -119,7 +119,7 @@ (ert-deftest mastodon-tl--byline-regular-with-avatar () "Should format the regular toot correctly." - (let ((mastodon-media-show-avatars-p t) + (let ((mastodon-tl--show-avatars-p t) (timestamp (cdr (assoc 'created_at mastodon-tl-test-base-toot)))) (with-mock (stub create-image => '(image "fake data")) @@ -134,7 +134,7 @@ (ert-deftest mastodon-tl--byline-boosted () "Should format the boosted toot correctly." - (let* ((mastodon-media-show-avatars-p nil) + (let* ((mastodon-tl--show-avatars-p nil) (toot (cons '(reblogged . t) mastodon-tl-test-base-toot)) (timestamp (cdr (assoc 'created_at toot)))) (with-mock @@ -148,7 +148,7 @@ (ert-deftest mastodon-tl--byline-favorited () "Should format the favourited toot correctly." - (let* ((mastodon-media-show-avatars-p nil) + (let* ((mastodon-tl--show-avatars-p nil) (toot (cons '(favourited . t) mastodon-tl-test-base-toot)) (timestamp (cdr (assoc 'created_at toot)))) (with-mock @@ -163,7 +163,7 @@ (ert-deftest mastodon-tl--byline-boosted/favorited () "Should format the boosted & favourited toot correctly." - (let* ((mastodon-media-show-avatars-p nil) + (let* ((mastodon-tl--show-avatars-p nil) (toot `((favourited . t) (reblogged . t) ,@mastodon-tl-test-base-toot)) (timestamp (cdr (assoc 'created_at toot)))) (with-mock @@ -177,7 +177,7 @@ (ert-deftest mastodon-tl--byline-reblogged () "Should format the reblogged toot correctly." - (let* ((mastodon-media-show-avatars-p nil) + (let* ((mastodon-tl--show-avatars-p nil) (toot mastodon-tl-test-base-boosted-toot) (original-toot (cdr (assoc 'reblog mastodon-tl-test-base-boosted-toot))) (timestamp (cdr (assoc 'created_at toot))) @@ -197,7 +197,7 @@ (ert-deftest mastodon-tl--byline-reblogged-with-avatars () "Should format the reblogged toot correctly." - (let* ((mastodon-media-show-avatars-p t) + (let* ((mastodon-tl--show-avatars-p t) (toot mastodon-tl-test-base-boosted-toot) (original-toot (cdr (assoc 'reblog mastodon-tl-test-base-boosted-toot))) (timestamp (cdr (assoc 'created_at toot))) @@ -218,7 +218,7 @@ (ert-deftest mastodon-tl--byline-reblogged-boosted/favorited () "Should format the reblogged toot that was also boosted & favoritedcorrectly." - (let* ((mastodon-media-show-avatars-p nil) + (let* ((mastodon-tl--show-avatars-p nil) (toot `((favourited . t) (reblogged . t) ,@mastodon-tl-test-base-boosted-toot)) (original-toot (cdr (assoc 'reblog mastodon-tl-test-base-boosted-toot))) (timestamp (cdr (assoc 'created_at toot))) -- cgit v1.2.3 From c0708e9338de45415c0b70019cf45ee9a5bad230 Mon Sep 17 00:00:00 2001 From: Holger Dürer Date: Tue, 16 May 2017 21:44:10 +0100 Subject: Replace uses of replace-regexp with search-forward and replace-match. --- lisp/mastodon-inspect.el | 6 ++++-- lisp/mastodon-tl.el | 4 +++- lisp/mastodon-toot.el | 5 ++++- 3 files changed, 11 insertions(+), 4 deletions(-) (limited to 'lisp/mastodon-inspect.el') diff --git a/lisp/mastodon-inspect.el b/lisp/mastodon-inspect.el index f5fcd81..0457e74 100644 --- a/lisp/mastodon-inspect.el +++ b/lisp/mastodon-inspect.el @@ -71,8 +71,10 @@ (with-current-buffer buffer (let ((toot (mastodon-inspect--download-single-toot toot-id ))) (mastodon-tl--toot toot) - (replace-regexp "\n\n\n | " "\n | " nil (point-min) (point-max)) - (mastodon-media--inline-images))) + (goto-char (point-min)) + (while (search-forward "\n\n\n | " nil t) + (replace-match "\n | ")) + (mastodon-media--inline-images))) (switch-to-buffer-other-window buffer) (mastodon-mode))) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index edefae9..72883fc 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -234,7 +234,9 @@ also render the html" (defun mastodon-tl--timeline (toots) "Display each toot in TOOTS." (mapc 'mastodon-tl--toot toots) - (replace-regexp "\n\n\n | " "\n | " nil (point-min) (point-max)) + (goto-char (point-min)) + (while (search-forward "\n\n\n | " nil t) + (replace-match "\n | ")) (mastodon-media--inline-images)) (defun mastodon-tl--get-update-function (&optional buffer) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index ffe6454..296f95f 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -56,7 +56,10 @@ Remove MARKER if RM is non-nil." (let ((inhibit-read-only t) (bol (progn (move-beginning-of-line nil) (point))) (eol (progn (move-end-of-line nil) (point)))) - (when rm (replace-regexp (format "(%s) " marker) "" nil bol eol)) + (when rm + (goto-char bol) + (if (search-forward (format "(%s) " marker) eol t) + (replace-match ""))) (move-beginning-of-line nil) (mastodon-tl--goto-next-toot) (unless rm -- cgit v1.2.3 From 349a46befedafae39ab05598c1005f9f2c82fadf Mon Sep 17 00:00:00 2001 From: alexjgriffith Date: Wed, 17 May 2017 10:34:34 -0400 Subject: replaced declare-function with autoload --- lisp/mastodon-auth.el | 4 ++-- lisp/mastodon-client.el | 4 ++-- lisp/mastodon-http.el | 2 +- lisp/mastodon-inspect.el | 12 ++++++------ lisp/mastodon-tl.el | 12 ++++++------ lisp/mastodon-toot.el | 30 +++++++++++++++--------------- lisp/mastodon.el | 24 ++++++++++++------------ 7 files changed, 44 insertions(+), 44 deletions(-) (limited to 'lisp/mastodon-inspect.el') diff --git a/lisp/mastodon-auth.el b/lisp/mastodon-auth.el index 68c4d21..513fbc2 100644 --- a/lisp/mastodon-auth.el +++ b/lisp/mastodon-auth.el @@ -31,8 +31,8 @@ (require 'plstore) -(declare-function mastodon-client "mastodon-client") -(declare-function mastodon-http--post "mastodon-http") +(autoload 'mastodon-client "mastodon-client") +(autoload 'mastodon-http--post "mastodon-http") (defvar mastodon-instance-url) (defgroup mastodon-auth nil diff --git a/lisp/mastodon-client.el b/lisp/mastodon-client.el index 3a9a606..b4fcbdb 100644 --- a/lisp/mastodon-client.el +++ b/lisp/mastodon-client.el @@ -30,8 +30,8 @@ ;;; Code: (require 'plstore) -(declare-function mastodon-http--api "mastodon-http") -(declare-function mastodon-http--post "mastodon-http") +(autoload 'mastodon-http--api "mastodon-http") +(autoload 'mastodon-http--post "mastodon-http") (defcustom mastodon-client--token-file (concat user-emacs-directory "mastodon.plstore") diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el index 9f178c4..0f71f68 100644 --- a/lisp/mastodon-http.el +++ b/lisp/mastodon-http.el @@ -32,7 +32,7 @@ (require 'json) (defvar mastodon-instance-url) (defvar mastodon-auth--token) -(declare-function mastodon-auth--access-token "mastodon-auth") +(autoload 'mastodon-auth--access-token "mastodon-auth") (defvar mastodon-http--api-version "v1") diff --git a/lisp/mastodon-inspect.el b/lisp/mastodon-inspect.el index 0457e74..9aee7dc 100644 --- a/lisp/mastodon-inspect.el +++ b/lisp/mastodon-inspect.el @@ -28,12 +28,12 @@ ;; Some tools to help inspect / debug mastodon.el ;;; Code: -(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") +(autoload 'mastodon-http--api "mastodon-http") +(autoload 'mastodon-http--get-json "mastodon-http") +(autoload 'mastodon-media--inline-images "mastodon-media") +(autoload 'mastodon-mode "mastodon") +(autoload 'mastodon-tl--property "mastodon-tl") +(autoload 'mastodon-tl--toot "mastodon-tl") (defgroup mastodon-inspect nil "Tools to help inspect toots." diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 72883fc..b84bc94 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -33,12 +33,12 @@ (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") +(autoload 'mastodon-http--api "mastodon-http") +(autoload 'mastodon-http--get-json "mastodon-http") +(autoload 'mastodon-media--get-avatar-rendering "mastodon-media") +(autoload 'mastodon-media--get-media-link-rendering "mastodon-media") +(autoload 'mastodon-media--inline-images "mastodon-media") +(autoload 'mastodon-mode "mastodon") (defvar mastodon-toot-timestamp-format) (defgroup mastodon-tl nil diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 296f95f..eaf5339 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -32,13 +32,13 @@ (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") +(autoload 'mastodon-http--api "mastodon-http") +(autoload 'mastodon-http--post "mastodon-http") +(autoload 'mastodon-http--triage "mastodon-http") +(autoload 'mastodon-tl--field "mastodon-tl") +(autoload 'mastodon-tl--goto-next-toot "mastodon-tl") +(autoload 'mastodon-tl--property "mastodon-tl") +(autoload 'mastodon-toot "mastodon") (defvar mastodon-toot-mode-map (let ((map (make-sparse-keymap))) @@ -166,28 +166,28 @@ Set `mastodon-toot--content-warning' to nil." (mapcar (lambda (b) (setf (car b) (vector prefix (car b))) b) - bindings))) + bindings))) (defun mastodon-toot--format-kbind-command (cmd) "Format CMD to be more readable. e.g. mastodon-toot--send -> Send." (let* ((str (symbol-name cmd)) - (re "--\\(.*\\)$") - (str2 (save-match-data - (string-match re str) - (match-string 1 str)))) + (re "--\\(.*\\)$") + (str2 (save-match-data + (string-match re str) + (match-string 1 str)))) (capitalize (replace-regexp-in-string "-" " " str2)))) (defun mastodon-toot--format-kbind (kbind) "Format a single keybinding, KBIND, for display in documentation." (let ((key (help-key-description (car kbind) nil)) - (command (mastodon-toot--format-kbind-command (cdr kbind)))) + (command (mastodon-toot--format-kbind-command (cdr kbind)))) (format "\t%s - %s" key command))) (defun mastodon-toot--format-kbinds (kbinds) "Format a list keybindings, KBINDS, for display in documentation." (mapconcat 'identity (cons "" (mapcar #'mastodon-toot--format-kbind kbinds)) - "\n")) + "\n")) (defun mastodon-toot--make-mode-docs () "Create formatted documentation text for the mastodon-toot-mode." @@ -217,7 +217,7 @@ If REPLY-TO-ID is provided, set the MASTODON-TOOT--REPLY-TO-ID var." If REPLY-TO-USER is provided, inject their handle into the message. If REPLY-TO-ID is provided, set the MASTODON-TOOT--REPLY-TO-ID var." (let* ((buffer-exists (get-buffer "*new toot*")) - (buffer (or buffer-exists (get-buffer-create "*new toot*")))) + (buffer (or buffer-exists (get-buffer-create "*new toot*")))) (switch-to-buffer-other-window buffer) (when (not buffer-exists) (mastodon-toot--display-docs) diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 9f7257e..6e3a5dc 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -32,18 +32,18 @@ ;;; Code: (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") +(autoload 'mastodon-tl--get-federated-timeline "mastodon-tl") +(autoload 'mastodon-tl--get-home-timeline "mastodon-tl") +(autoload 'mastodon-tl--get-local-timeline "mastodon-tl") +(autoload 'mastodon-tl--get-tag-timeline "mastodon-tl") +(autoload 'mastodon-tl--goto-next-toot "mastodon-tl") +(autoload 'mastodon-tl--goto-prev-toot "mastodon-tl") +(autoload 'mastodon-tl--thread "mastodon-tl") +(autoload 'mastodon-tl--update "mastodon-tl") +(autoload 'mastodon-toot--compose-buffer "mastodon-toot") +(autoload 'mastodon-toot--reply "mastodon-toot") +(autoload 'mastodon-toot--toggle-boost "mastodon-toot") +(autoload 'mastodon-toot--toggle-favourite "mastodon-toot") (defgroup mastodon nil "Interface with Mastodon." -- cgit v1.2.3 From 8c841d2ad3d60997f7aea725da86b83ac80dcd61 Mon Sep 17 00:00:00 2001 From: Johnson Denen Date: Thu, 18 May 2017 13:28:40 -0400 Subject: Bump to v0.7.0 --- lisp/mastodon-auth.el | 2 +- lisp/mastodon-client.el | 2 +- lisp/mastodon-http.el | 2 +- lisp/mastodon-inspect.el | 2 +- lisp/mastodon-media.el | 2 +- lisp/mastodon-tl.el | 2 +- lisp/mastodon-toot.el | 2 +- lisp/mastodon.el | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) (limited to 'lisp/mastodon-inspect.el') diff --git a/lisp/mastodon-auth.el b/lisp/mastodon-auth.el index 513fbc2..ed756f8 100644 --- a/lisp/mastodon-auth.el +++ b/lisp/mastodon-auth.el @@ -2,7 +2,7 @@ ;; Copyright (C) 2017 Johnson Denen ;; Author: Johnson Denen -;; Version: 0.6.3 +;; Version: 0.7.0 ;; Homepage: https://github.com/jdenen/mastodon.el ;; Package-Requires: ((emacs "24.4")) diff --git a/lisp/mastodon-client.el b/lisp/mastodon-client.el index b4fcbdb..cbb276b 100644 --- a/lisp/mastodon-client.el +++ b/lisp/mastodon-client.el @@ -2,7 +2,7 @@ ;; Copyright (C) 2017 Johnson Denen ;; Author: Johnson Denen -;; Version: 0.6.3 +;; Version: 0.7.0 ;; Homepage: https://github.com/jdenen/mastodon.el ;; Package-Requires: ((emacs "24.4")) diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el index 0f71f68..1e6e037 100644 --- a/lisp/mastodon-http.el +++ b/lisp/mastodon-http.el @@ -2,7 +2,7 @@ ;; Copyright (C) 2017 Johnson Denen ;; Author: Johnson Denen -;; Version: 0.6.3 +;; Version: 0.7.0 ;; Package-Requires: ((emacs "24.4")) ;; Homepage: https://github.com/jdenen/mastodon.el diff --git a/lisp/mastodon-inspect.el b/lisp/mastodon-inspect.el index 9aee7dc..29368a9 100644 --- a/lisp/mastodon-inspect.el +++ b/lisp/mastodon-inspect.el @@ -2,7 +2,7 @@ ;; Copyright (C) 2017 Johnson Denen ;; Author: Johnson Denen -;; Version: 0.6.3 +;; Version: 0.7.0 ;; Package-Requires: ((emacs "24.4")) ;; Homepage: https://github.com/jdenen/mastodon.el diff --git a/lisp/mastodon-media.el b/lisp/mastodon-media.el index 671f159..f5d67ca 100644 --- a/lisp/mastodon-media.el +++ b/lisp/mastodon-media.el @@ -2,7 +2,7 @@ ;; Copyright (C) 2017 Johnson Denen ;; Author: Johnson Denen -;; Version: 0.6.3 +;; Version: 0.7.0 ;; Homepage: https://github.com/jdenen/mastodon.el ;; Package-Requires: ((emacs "24.4")) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index b84bc94..eeed6b5 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -2,7 +2,7 @@ ;; Copyright (C) 2017 Johnson Denen ;; Author: Johnson Denen -;; Version: 0.6.3 +;; Version: 0.7.0 ;; Homepage: https://github.com/jdenen/mastodon.el ;; Package-Requires: ((emacs "24.4")) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index eaf5339..7d33116 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -2,7 +2,7 @@ ;; Copyright (C) 2017 Johnson Denen ;; Author: Johnson Denen -;; Version: 0.6.3 +;; Version: 0.7.0 ;; Homepage: https://github.com/jdenen/mastodon.el ;; Package-Requires: ((emacs "24.4")) diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 6e3a5dc..2bf5e84 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -2,7 +2,7 @@ ;; Copyright (C) 2017 Johnson Denen ;; Author: Johnson Denen -;; Version: 0.6.3 +;; Version: 0.7.0 ;; Package-Requires: ((emacs "24.4")) ;; Homepage: https://github.com/jdenen/mastodon.el -- cgit v1.2.3