Last active
October 12, 2015 02:06
-
-
Save karino2/39507591d82e6bd5e831 to your computer and use it in GitHub Desktop.
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
(global-set-key (kbd "C-t") 'convert-to-list) | |
(global-set-key (kbd "C-r") 'insert-from-osx) | |
(global-set-key (kbd "C-u") 'lines-to-list) | |
(global-set-key (kbd "C-o") 'nums-to-lists) | |
(defun nums-to-lists() | |
(interactive) | |
(save-excursion | |
(move-beginning-of-line 1) | |
(search-forward "1 ") | |
(let ((slist '())) | |
(setq slist (cons (buffer-substring (point) (progn (search-forward "2 ") | |
(- (point) 2))) | |
slist)) | |
(setq slist (cons (buffer-substring (point) (progn (search-forward "3 ") | |
(- (point) 2))) | |
slist)) | |
(setq slist (cons (buffer-substring (point) (progn (search-forward "4 ") | |
(- (point) 2))) | |
slist)) | |
(setq slist (cons (buffer-substring (point) (progn (move-end-of-line 1) (point))) | |
slist)) | |
(setq slist (reverse slist)) | |
(next-line) | |
(insert-list-with-quote slist) | |
(paste-to-osx | |
(buffer-substring (progn (move-beginning-of-line 1) (point)) | |
(progn (move-end-of-line 1) (point)))))) | |
(move-beginning-of-line 1) | |
(save-excursion | |
(insert "\n\n"))) | |
(defun lines-to-list() | |
(interactive) | |
(copy-from-osx) | |
(save-excursion | |
(let ((beg (point)) | |
(slist '()) | |
end | |
str) | |
(yank) | |
(setq end (point)) | |
(goto-char beg) | |
(while (<= (point) end) | |
(move-beginning-of-line 1) | |
(setq str (buffer-substring (point) (progn (move-end-of-line 1) (point)))) | |
(setq slist (cons str slist)) | |
(next-line)) | |
(setq slist (reverse slist)) | |
(delete-region beg end) | |
(goto-char beg) | |
(insert-list-with-quote slist) | |
(setq beg (progn (move-beginning-of-line 1) (point))) | |
(move-end-of-line 1) | |
(paste-to-osx (buffer-substring beg (point))) | |
(delete-region beg (point))))) | |
(defun replace-separator(beg end) | |
(interactive) | |
(replace-regexp "(?[0-9]?)" "?" nil beg end) | |
(replace-regexp "([0-9]?)?" "?" nil beg end) | |
(replace-regexp "@" "?" nil beg end) | |
) | |
(defun insert-from-osx() | |
(interactive) | |
(copy-from-osx) | |
(save-excursion | |
(let ((beg (point)) | |
end) | |
(save-excursion | |
(yank) | |
(setq end (point))) | |
(replace-separator beg end)))) | |
(defun convert-to-list() | |
(interactive) | |
(save-excursion | |
(move-beginning-of-line 1) | |
(setq beg (point)) | |
(setq end (progn | |
(move-end-of-line 1) | |
(point))) | |
(setq str (buffer-substring beg end)) | |
(setq str (replace-regexp-in-string "\\?+" "?" str)) | |
(setq slist (remove-empty (split-string str "?"))) | |
(next-line) | |
(insert-list-with-quote slist) | |
(setq beg (progn (move-beginning-of-line 1) (point))) | |
(move-end-of-line 1) | |
(paste-to-osx (buffer-substring beg (point)))) | |
(move-beginning-of-line 1) | |
(save-excursion | |
(insert "\n\n"))) | |
(defun chop-space(str) | |
(replace-regexp-in-string " *$" "" (replace-regexp-in-string "^ *" "" str) )) | |
(defun withq(str) | |
(concat "\"" (chop-space str) "\"")) | |
(defun insert-list-with-quote(slist) | |
(if (null slist) | |
(progn | |
(backward-delete-char 1) | |
'() | |
) | |
(insert (withq (car slist))) | |
(insert ",") | |
(insert-list-with-quote (cdr slist)))) | |
(defun remove-empty(slist) | |
(if (null slist) | |
'() | |
(if (equal (car slist) "") | |
(cdr slist) | |
(cons (car slist) (remove-empty (cdr slist)))))) | |
; http://blog.lathi.net/articles/2007/11/07/sharing-the-mac-clipboard-with-emacs | |
(defun copy-from-osx () | |
(shell-command-to-string "pbpaste")) | |
(defun paste-to-osx (text &optional push) | |
(let ((process-connection-type nil)) | |
(let ((proc (start-process "pbcopy" "*Messages*" "pbcopy"))) | |
(process-send-string proc text) | |
(process-send-eof proc)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment