Rename to sewyg

`sie.el' is already taken.
This commit is contained in:
Tom Willemsen 2012-08-07 20:11:10 +02:00
parent f76e03623c
commit 98964af3e7
2 changed files with 44 additions and 44 deletions

View file

@ -1,6 +1,6 @@
* SIE * SEWYG
Scuttle Interface for Emacs Scuttle in Emacs is What You Get
This is a simple set of functions that will try to connect to a This is a simple set of functions that will try to connect to a
scuttle instance and access bookmarks through its api. scuttle instance and access bookmarks through its api.

View file

@ -1,4 +1,4 @@
;;; sie.el --- Scuttle Interface for Emacs ;;; sewyg.el --- Scuttle in Emacs is What You Get
;; Copyright (C) 2012 Tom Willemsen <tom@ryuslash.org> ;; Copyright (C) 2012 Tom Willemsen <tom@ryuslash.org>
@ -29,66 +29,66 @@
(require 'auth-source) (require 'auth-source)
(require 'xml) (require 'xml)
(defvar sie-scuttle-api-url "http://pegas/scuttle/api/" (defvar sewyg-scuttle-api-url "http://pegas/scuttle/api/"
"Location of the Scuttle API.") "Location of the Scuttle API.")
(defvar sie-user nil (defvar sewyg-user nil
"Username to authenticate scuttle with.") "Username to authenticate scuttle with.")
(defvar sie-password nil (defvar sewyg-password nil
"Password to authenticate scuttle with.") "Password to authenticate scuttle with.")
(defgroup sie nil (defgroup sewyg nil
"Scuttle Interface for Emacs." "Scuttle Interface for Emacs."
:group 'applications) :group 'applications)
(defface sie-description (defface sewyg-description
'((t (:inherit shadow))) '((t (:inherit shadow)))
"Face for bookmark descriptions." "Face for bookmark descriptions."
:group 'sie) :group 'sewyg)
(defmacro sie-get-prop (prop post) (defmacro sewyg-get-prop (prop post)
`(cdr (assq ,prop (cadr ,post)))) `(cdr (assq ,prop (cadr ,post))))
(defmacro sie-getset (var prompt &optional passwd) (defmacro sewyg-getset (var prompt &optional passwd)
"Ask the user for, and then save, VAR with PROMPT. Use "Ask the user for, and then save, VAR with PROMPT. Use
`read-passwd' if PASSWD is non-nil and `read-string' otherwise." `read-passwd' if PASSWD is non-nil and `read-string' otherwise."
`(or ,var (setq ,var (,(if passwd 'read-passwd 'read-string) `(or ,var (setq ,var (,(if passwd 'read-passwd 'read-string)
,prompt)))) ,prompt))))
(defun sie-get-credentials () (defun sewyg-get-credentials ()
"Search in `auth-sources' or ask the user for a username and "Search in `auth-sources' or ask the user for a username and
password to log in with." password to log in with."
(let ((credentials (auth-source-search :max 1 :host sie-scuttle-api-url (let ((credentials (auth-source-search :max 1 :host sewyg-scuttle-api-url
:type 'netrc :type 'netrc
:require '(:user :secret) :require '(:user :secret)
:user sie-user))) :user sewyg-user)))
(if credentials (if credentials
(setq sie-user (plist-get (car credentials) :user) (setq sewyg-user (plist-get (car credentials) :user)
sie-password (plist-get (car credentials) :secret)) sewyg-password (plist-get (car credentials) :secret))
(sie-getset sie-user "Username: ") (sewyg-getset sewyg-user "Username: ")
(sie-getset sie-password "Password: " t)))) (sewyg-getset sewyg-password "Password: " t))))
(defun sie--password () (defun sewyg--password ()
"Return the stored password. If `sie-password' is a "Return the stored password. If `sewyg-password' is a
function, return the result of that function, otherwise return it function, return the result of that function, otherwise return it
as-is." as-is."
(if (functionp sie-password) (if (functionp sewyg-password)
(funcall sie-password) (funcall sewyg-password)
sie-password)) sewyg-password))
(defun sie-credential-header () (defun sewyg-credential-header ()
"Generate the Authorization header to send along to Scuttle." "Generate the Authorization header to send along to Scuttle."
(concat "Basic " (base64-encode-string (concat "Basic " (base64-encode-string
(concat sie-user ":" (sie--password))))) (concat sewyg-user ":" (sewyg--password)))))
(defun sie-send-command (command) (defun sewyg-send-command (command)
"Send a request to sie for COMMAND." "Send a request to sewyg for COMMAND."
(let* ((url-request-extra-headers (let* ((url-request-extra-headers
`(("Authorization" . ,(sie-credential-header)))) `(("Authorization" . ,(sewyg-credential-header))))
(buffer (url-retrieve-synchronously (buffer (url-retrieve-synchronously
(url-encode-url (url-encode-url
(concat sie-scuttle-api-url command)))) (concat sewyg-scuttle-api-url command))))
response) response)
(with-current-buffer buffer (with-current-buffer buffer
(goto-char (point-min)) (goto-char (point-min))
@ -98,21 +98,21 @@ as-is."
(kill-buffer buffer) (kill-buffer buffer)
response)) response))
(define-derived-mode sie-list-mode special-mode "Sie" (define-derived-mode sewyg-list-mode special-mode "Sewyg"
"Major mode for viewing bookmarks from scuttle. "Major mode for viewing bookmarks from scuttle.
\\{avandu-overview-map} \\{avandu-overview-map}
\\<avandu-overview-map>") \\<avandu-overview-map>")
;;;###autoload ;;;###autoload
(defun sie-bookmark-list (tag) (defun sewyg-bookmark-list (tag)
"Show a list of all the bookmarks collected." "Show a list of all the bookmarks collected."
(interactive "MTag: ") (interactive "MTag: ")
(unless (and sie-user sie-password) (unless (and sewyg-user sewyg-password)
(sie-get-credentials)) (sewyg-get-credentials))
(let ((buffer (get-buffer-create "*sie-bookmarks*")) (let ((buffer (get-buffer-create "*sewyg-bookmarks*"))
(result (sie-send-command (concat "posts_all.php?tag=" tag)))) (result (sewyg-send-command (concat "posts_all.php?tag=" tag))))
(with-current-buffer buffer (with-current-buffer buffer
(setq buffer-read-only nil) (setq buffer-read-only nil)
(erase-buffer) (erase-buffer)
@ -121,16 +121,16 @@ as-is."
(unless (stringp elt) (unless (stringp elt)
(when (eq 'post (car elt)) (when (eq 'post (car elt))
(insert-button (insert-button
(sie-get-prop 'description elt) (sewyg-get-prop 'description elt)
'link (sie-get-prop 'href elt) 'link (sewyg-get-prop 'href elt)
'action #'(lambda (button) 'action #'(lambda (button)
(browse-url (button-get button 'link)))) (browse-url (button-get button 'link))))
(insert-char ?\n) (insert-char ?\n)
(let ((pos (point))) (let ((pos (point)))
(insert-char ?\t) (insert-char ?\t)
(insert (propertize (sie-get-prop 'description elt) (insert (propertize (sewyg-get-prop 'description elt)
'face 'sie-description)) 'face 'sewyg-description))
(fill-region pos (point))) (fill-region pos (point)))
(insert-char ?\n) (insert-char ?\n)
@ -141,21 +141,21 @@ as-is."
(insert-button (insert-button
tag tag
'action #'(lambda (button) 'action #'(lambda (button)
(sie-bookmark-list (button-label button)))) (sewyg-bookmark-list (button-label button))))
(insert-char ?\ )) (insert-char ?\ ))
(split-string (sie-get-prop 'tag elt))) (split-string (sewyg-get-prop 'tag elt)))
(fill-region pos (point))) (fill-region pos (point)))
(insert-char ?\n 2)))) (insert-char ?\n 2))))
(cdr (assq 'posts result))) (cdr (assq 'posts result)))
(setq buffer-read-only t) (setq buffer-read-only t)
(goto-char (point-min)) (goto-char (point-min))
(sie-list-mode)) (sewyg-list-mode))
(switch-to-buffer buffer))) (switch-to-buffer buffer)))
(provide 'sie) (provide 'sewyg)
;;; sie.el ends here ;;; sewyg.el ends here
;; (posts-update) ;; (posts-update)
;; (posts-add url description &keyword extended tags date replace shared) ;; (posts-add url description &keyword extended tags date replace shared)
;; (posts-delete url) ;; (posts-delete url)