Skip to content

Commit

Permalink
Add a switch of vim-style command interface
Browse files Browse the repository at this point in the history
* twittering-mode.el (twittering-defcommand): add
(twittering-commands): add
(twittering-command-history): add
(twittering-command-mode): add a switch of command interface
  • Loading branch information
hayamiz committed Jan 18, 2010
1 parent 8a7db54 commit 1f4a695
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 20 deletions.
7 changes: 7 additions & 0 deletions ChangeLog
Expand Up @@ -767,6 +767,13 @@
(twittering-http-post-default-sentinel): use the same argument
format of http-get-default-sentinel

2009-12-17 Yuto Hayamizu <y.hayamizu@gmail.com>

* twittering-mode.el (twittering-defcommand): add
(twittering-commands): add
(twittering-command-history): add
(twittering-command-mode): add a switch of command interface

2009-12-16 Yuto Hayamizu <y.hayamizu@gmail.com>

* twittering-mode.el (twittering-tinyurl-replace-at-point):
Expand Down
52 changes: 32 additions & 20 deletions twittering-mode.el
Expand Up @@ -200,6 +200,15 @@ when it conflict with your input method (such as AquaSKK, etc.)")
SSL connections use 'curl' command as a backend.")

(defvar twittering-command-mode t
"If this is non-nil, vim-style command interface is enabled:
`twittering-command-prompt' prompts you to specify a command. It reads a command name with completion, and executes the command."
)
(defun twittering-command-mode ()
(interactive)
(setq twittering-command-mode (not twittering-command-mode)))

(defvar twittering-buffer "*twittering*")
(defun twittering-buffer ()
(twittering-get-or-generate-buffer twittering-buffer))
Expand Down Expand Up @@ -2893,14 +2902,18 @@ The return value is nil or a positive integer less than POS."
(switch-to-buffer (other-buffer)))

;;;
;;; Vim like command interface
;;; Vim-style command interface
;;;

(defvar twittering-commands nil)
(defvar twittering-commands nil
"An assoc list of commands to be executed by `twittering-command-prompt'.
You can define commands with `twittering-defcommand'.")

(defvar twittering-command-history nil)
(defvar twittering-command-history nil
"History of commands executed by `twittering-command-prompt' are saved in this variable.")

(defun twittering-defcommand (command function)
"Define a command for twittering-mode. Call `twittering-command-prompt' to invoke commands."
(unless (symbolp function)
(error (format "twittering-defcommand: `function' must be as symbol")))
(setq command (format "%s" command))
Expand All @@ -2911,42 +2924,41 @@ The return value is nil or a positive integer less than POS."
(cons command function)))))

(defun twittering-command-prompt ()
"Read a command in the minibuffer with completion.
Commands are defined by `twittering-defcommand'."
(interactive)
(let ((command
(completing-read ":"
(mapcar 'car twittering-commands)
nil t nil 'twittering-command-history)))
(funcall (cdr (assoc command twittering-commands)))))
(when twittering-command-mode
(let ((command
(completing-read ":"
(mapcar 'car twittering-commands)
nil t nil 'twittering-command-history)))
(funcall (cdr (assoc command twittering-commands))))))

;;; Commands: timeline
(twittering-defcommand "friends-timeline" 'twittering-friends-timeline)
(twittering-defcommand "friends-timeline" 'twittering-friends-timeline)
(twittering-defcommand "public-timeline" 'twittering-public-timeline)
(twittering-defcommand "replies" 'twittering-replies-timeline)
(twittering-defcommand "list" 'twittering-other-user-list-interactive)

;;; Commands: switch
(twittering-defcommand "icon" 'twittering-icon-mode)
(twittering-defcommand "proxy" 'twittering-toggle-proxy)
(twittering-defcommand "toggle-proxy" 'twittering-toggle-proxy)

;;; Commands: action
(twittering-defcommand "update" 'twittering-update-status-interactive)
(twittering-defcommand "post" 'twittering-update-status-interactive)
(twittering-defcommand "follow" 'twittering-follow)
(twittering-defcommand "favorite" 'twittering-favorite)
(twittering-defcommand "retweet" 'twittering-retweet)
(twittering-defcommand "hashtag-set" 'twittering-set-current-hashtag)
(twittering-defcommand "hashtag" 'twittering-set-current-hashtag)
(twittering-defcommand "set-hashtag" 'twittering-set-current-hashtag)
(twittering-defcommand "open-user-page" 'twittering-view-user-page)
; (twittering-defcommand "open-in-browser" 'twittering-view-user-page)
(twittering-defcommand "direct-message" 'twittering-direct-message)
(twittering-defcommand "send-direct-message" 'twittering-direct-message)
(twittering-defcommand "list" 'twittering-other-user-list-interactive)
(twittering-defcommand "icon" 'twittering-icon-mode)
(twittering-defcommand "suspend" 'twittering-suspend)
(twittering-defcommand "close" 'twittering-suspend)
(twittering-defcommand "proxy" 'twittering-toggle-proxy)
(twittering-defcommand "toggle-proxy" 'twittering-toggle-proxy)

;; (twittering-defcommand "" 'twittering-user-timeline)
;; (twittering-defcommand "" 'twittering-erase-old-statuses)
;; (twittering-defcommand "" 'twittering-current-timeline)
;; (twittering-defcommand "" 'beginning-of-buffer)
;; (twittering-defcommand "" 'twittering-scroll-mode)

;;;###autoload
(defun twit ()
Expand Down

0 comments on commit 1f4a695

Please sign in to comment.