Created
May 7, 2011 12:48
-
-
Save sonota88/960469 to your computer and use it in GitHub Desktop.
my-imcap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require 'imcap) | |
(setq imcap-file-name-format "%Y-%m-%d-%H%M%S.png") | |
(setq imcap-directory "imcap") | |
(setq imcap-capture-delay 5) | |
(defun imcap-capture-command-format () | |
(concat " sleep " | |
(format "%s" imcap-capture-delay) | |
" ; " | |
" beep; " | |
" scrot %s --select " | |
)) | |
(defun imcap-paste-format () | |
(cond | |
((string= major-mode "org-mode") "file:%s") | |
((and (boundp 'howm-mode) | |
howm-mode) | |
">>> %s") | |
(t "[img:%s]") ; cacoo | |
)) | |
(defun my-imcap-capture (delay) | |
(interactive | |
(list (read-string "Delay seconds: " (format "%s" imcap-capture-delay)))) | |
(setq imcap-capture-delay delay) | |
(imcap-capture)) | |
(global-set-key (kbd "<C-print>") 'my-imcap-capture) | |
;; cacoo.elをorg-modeで使ってみた | |
;; http://sheephead.homelinux.org/2011/02/09/6582/ | |
(setq cacoo:img-regexp | |
'("\\[img:\\([^]]*\\)\\]" ; default | |
"^file:\\(.+\.\\(jpg\\|png\\)\\)" ; org | |
"^>>> \\(.+\.\\(jpg\\|png\\)\\)" ; howm | |
)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- imcap.el-orig 2011-05-07 21:25:25.419744003 +0900 | |
+++ imcap.el 2011-05-07 22:04:03.227744003 +0900 | |
@@ -5,11 +5,10 @@ | |
;;; var | |
-(defvar imcap-capture-command-format "import %s") | |
-(defvar imcap-paste-format ">>> %s") | |
(defvar imcap-file-name-format "%Y-%m-%d-%H%M%S.jpg") | |
(defvar imcap-directory nil) ;; nil means current directory | |
; (defvar imcap-directory "~/imcap") | |
+(defvar imcap-capture-delay 5) | |
;;; command | |
@@ -17,17 +16,18 @@ | |
(interactive) | |
(let* ((filename (format-time-string imcap-file-name-format (current-time))) | |
(fileloc (imcap-expand-file-name filename)) | |
- (command (format imcap-capture-command-format fileloc)) | |
- (paste (format imcap-paste-format | |
+ (command (format (imcap-capture-command-format) fileloc)) | |
+ (paste (format (imcap-paste-format) | |
(if imcap-directory | |
fileloc | |
filename)))) | |
+ (imcap-prepare-dir) | |
(when (and (file-exists-p fileloc) | |
(not (y-or-n-p ("File %s exists. Overwrite? " fileloc)))) | |
(error)) | |
(shell-command command) | |
- (insert paste) | |
- (imcap-display) | |
+ (insert paste "\n") | |
+ ;; (imcap-display) | |
(message fileloc))) | |
(defun imcap-display () | |
@@ -52,11 +52,13 @@ | |
;;; private | |
+(defun imcap-capture-command-format () "import %s") | |
+ | |
(defun imcap-expand-file-name (filename) | |
(abbreviate-file-name (expand-file-name filename imcap-directory))) | |
(defun imcap-goto-next-image () | |
- (let ((regexp (format (regexp-quote imcap-paste-format) | |
+ (let ((regexp (format (regexp-quote (imcap-paste-format)) | |
"\\(.*\\.\\(jpg\\|png\\|gif\\)\\)"))) | |
(re-search-forward regexp nil t))) | |
@@ -66,6 +68,16 @@ | |
(defun imcap-image-region () | |
(list (match-beginning 0) (match-end 0))) | |
+(defun imcap-prepare-dir () | |
+ (let ((image-dir (expand-file-name imcap-directory | |
+ default-directory))) | |
+ (when (and imcap-directory | |
+ (not (file-exists-p image-dir))) | |
+ (mkdir image-dir)))) | |
+ | |
+(defun imcap-paste-format () | |
+ ">>> %s") | |
+ | |
;;; provide | |
(provide 'imcap) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment