Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linter warnings #19

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 34 additions & 28 deletions org-gtasks.el
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
;;; org-gtasks.el --- Export/import all Google Tasks to org files.
;;; org-gtasks.el --- Export/import all Google Tasks to org files

;; Author: Julien Masson <[email protected]>
;; URL: https://github.com/JulienMasson/org-gtasks
;; Version: 0.1
;; Maintainer: massonju.eseo
;; Copyright (C) :2018-2019 Julien Masson all rights reserved.
;; Created: :30-08-18
;; Package-Requires: ((emacs "24") (cl-lib "0.5") (org "8.2.4"))
;; Package-Requires: ((emacs "26.1"))
;; Keywords: convenience,

;; This program is free software; you can redistribute it and/or modify
Expand All @@ -22,6 +22,10 @@
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;; Export/import all Google Tasks to org files

(require 'cl-lib)
(require 'deferred)
(require 'json)
Expand All @@ -36,7 +40,7 @@
refresh-token
tasklists)

(cl-defstruct tasklist
(cl-defstruct org-gtasks-tasklist
title
file
id
Expand Down Expand Up @@ -70,7 +74,7 @@
(defvar org-gtasks-accounts nil)

;; utils
(defun array-to-list (array)
(defun org-gtasks-array-to-list (array)
(mapcar 'identity array))

(defun org-gtasks-json-read ()
Expand All @@ -96,7 +100,7 @@
org-gtasks-accounts))

(defun org-gtasks-find-tasklist (tasklists title)
(cl-find-if (lambda (tasklist) (string= (tasklist-title tasklist) title))
(cl-find-if (lambda (tasklist) (string= (org-gtasks-tasklist-title tasklist) title))
tasklists))

;; request
Expand Down Expand Up @@ -266,10 +270,10 @@

(defun org-gtasks-write-to-org (account tasklist)
(let* ((default-directory (org-gtasks-directory account))
(file (tasklist-file tasklist))
(title (tasklist-title tasklist))
(file (org-gtasks-tasklist-file tasklist))
(title (org-gtasks-tasklist-title tasklist))
(header (format "#+FILETAGS: :%s:\n" title))
(tasks (tasklist-tasks tasklist))
(tasks (org-gtasks-tasklist-tasks tasklist))
(save-silently t))
(with-current-buffer (find-file-noselect file)
(erase-buffer)
Expand All @@ -283,26 +287,26 @@
(save-buffer))))

(defun org-gtasks-tasks-cb (account tasklist write-p data)
(setf (tasklist-tasks tasklist) (array-to-list (plist-get data :items)))
(message "Fetch %s done" (propertize (tasklist-title tasklist) 'face 'success))
(setf (org-gtasks-tasklist-tasks tasklist) (org-gtasks-array-to-list (plist-get data :items)))
(message "Fetch %s done" (propertize (org-gtasks-tasklist-title tasklist) 'face 'success))
(when write-p
(org-gtasks-write-to-org account tasklist)))

(defun org-gtasks-fetch-tasks (account write-p tasklist)
(let ((title (tasklist-title tasklist))
(id (tasklist-id tasklist)))
(let ((title (org-gtasks-tasklist-title tasklist))
(id (org-gtasks-tasklist-id tasklist)))
(message "Fetching %s ..." (propertize title 'face 'success))
(org-gtasks-request-fetch account
(format "%s/lists/%s/tasks" org-gtasks-default-url id)
(apply-partially #'org-gtasks-tasks-cb account tasklist write-p))))

(defun org-gtasks-tasklists-cb (account write-p data)
(when (plist-member data :items)
(dolist (item (array-to-list (plist-get data :items)))
(dolist (item (org-gtasks-array-to-list (plist-get data :items)))
(let* ((title (plist-get item :title))
(file (format "%s.org" title))
(id (plist-get item :id))
(tasklist (make-tasklist :title title :file file :id id)))
(tasklist (make-org-gtasks-tasklist :title title :file file :id id)))
(push tasklist (org-gtasks-tasklists account))
(org-gtasks-fetch-tasks account write-p tasklist)))))

Expand All @@ -314,7 +318,7 @@

(defun org-gtasks-fetch (account &optional listname)
(let* ((tasklists (org-gtasks-tasklists account))
(titles (mapcar 'tasklist-title tasklists))
(titles (mapcar 'org-gtasks-tasklist-title tasklists))
(collection (append (list "ALL") titles))
(target (if (null listname)
(completing-read "Fetch: " collection)
Expand All @@ -340,7 +344,7 @@
;; pull
(defun org-gtasks-pull (account &optional listname)
(let* ((tasklists (org-gtasks-tasklists account))
(titles (mapcar 'tasklist-title tasklists))
(titles (mapcar 'org-gtasks-tasklist-title tasklists))
(collection (append (list "ALL") titles))
(target (if (null listname)
(completing-read "Pull: " collection)
Expand Down Expand Up @@ -403,16 +407,16 @@
(replace-regexp-in-string org-gtasks-links-drawer-re "" notes))

(defun org-gtasks-build-tasks-data (tasklist)
(let ((title (tasklist-title tasklist))
(file (tasklist-file tasklist))
(tasklist-id (tasklist-id tasklist))
(tasks (tasklist-tasks tasklist))
(let ((title (org-gtasks-tasklist-title tasklist))
(file (org-gtasks-tasklist-file tasklist))
(org-gtasks-tasklist-id (org-gtasks-tasklist-id tasklist))
(tasks (org-gtasks-tasklist-tasks tasklist))
initial-data tasklist-data)
;; init data with all tasks id with type DELETE
(dolist (task tasks)
(let* ((task-id (plist-get task :id))
(url (format "%s/lists/%s/tasks/%s" org-gtasks-default-url
tasklist-id task-id)))
org-gtasks-tasklist-id task-id)))
(push (cons (plist-get task :id) (list url "DELETE" nil))
initial-data)))
;; loop over org elements
Expand All @@ -423,7 +427,7 @@
(let* ((id (org-element-property :ID hl))
(type (org-gtasks-find-type tasks id))
(url (concat (format "%s/lists/%s/tasks" org-gtasks-default-url
tasklist-id)
org-gtasks-tasklist-id)
(if (string= type "PATCH") (concat "/" id))))
(title (substring-no-properties (org-element-interpret-data
(org-element-property :title hl))))
Expand Down Expand Up @@ -499,7 +503,7 @@

(defun org-gtasks-push (account &optional listname)
(let* ((tasklists (org-gtasks-tasklists account))
(collection (mapcar 'tasklist-title tasklists))
(collection (mapcar 'org-gtasks-tasklist-title tasklists))
(collection (if (> (length collection) 1)
(append (list "ALL") collection)
collection))
Expand Down Expand Up @@ -533,7 +537,7 @@
(when-let* ((title (plist-get data :title))
(file (format "%s.org" title))
(id (plist-get data :id))
(tasklist (make-tasklist :title title :file file :id id)))
(tasklist (make-org-gtasks-tasklist :title title :file file :id id)))
(setf (org-gtasks-tasklists account)
(append (list tasklist) (org-gtasks-tasklists account)))
(org-gtasks-push-tasklists account (list tasklist)
Expand All @@ -552,7 +556,7 @@
(defun org-gtasks-add (account)
(let* ((local-files (org-gtasks-local-files account))
(tasklists (org-gtasks-tasklists account))
(files (mapcar 'tasklist-file tasklists))
(files (mapcar 'org-gtasks-tasklist-file tasklists))
(added (cl-set-difference local-files files :test #'string=))
(collection (if (> (length added) 1)
(append (list "ALL") added)
Expand All @@ -566,9 +570,9 @@
(defun org-gtasks-build-remove-data (tasklists removed)
(let (data)
(dolist (file removed)
(when-let* ((tasklist (cl-find-if (lambda (tl) (string= (tasklist-file tl) file))
(when-let* ((tasklist (cl-find-if (lambda (tl) (string= (org-gtasks-tasklist-file tl) file))
tasklists))
(id (tasklist-id tasklist))
(id (org-gtasks-tasklist-id tasklist))
(url (format "%s/users/@me/lists/%s" org-gtasks-default-url id)))
(push (list tasklist url "DELETE") data)))
data))
Expand All @@ -587,7 +591,7 @@
(defun org-gtasks-remove (account)
(let* ((local-files (org-gtasks-local-files account))
(tasklists (org-gtasks-tasklists account))
(files (mapcar 'tasklist-file tasklists))
(files (mapcar 'org-gtasks-tasklist-file tasklists))
(removed (cl-set-difference files local-files :test #'string=))
(collection (if (> (length removed) 1)
(append (list "ALL") removed)
Expand Down Expand Up @@ -630,6 +634,8 @@

(provide 'org-gtasks)

;;; org-gtasks.el ends here

;; Local Variables:
;; indent-tabs-mode: nil
;; tab-width: 8
Expand Down