Last active
November 10, 2017 08:32
-
-
Save tom-tan/31b6990e175dbdf4ae9120143c28f3dc to your computer and use it in GitHub Desktop.
Docker image 名や CWL ファイル名を挿入する関数群
This file contains 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
(defun insert-docker-image (image) | |
(interactive | |
(let* ((val (completing-read | |
"docker image: " | |
(split-string | |
(shell-command-to-string | |
"docker images --format \"{{.Repository}}:{{.Tag}}\"")) | |
'stringp))) | |
(list val))) | |
(insert image)) | |
(defun insert-cwl-file (cwl) | |
(interactive | |
(let* ((val (completing-read | |
"CWL file: " | |
(directory-files default-directory | |
nil (rx ".cwl" string-end)) | |
'stringp))) | |
(list val))) | |
(insert cwl)) | |
(defcustom bam-directory "/Users/tanjo/bams" | |
"A directory that stores BAM files." | |
:type 'stringp) | |
(defun insert-bam-file (bam) | |
(interactive | |
(let* ((val (completing-read | |
"BAM file: " | |
(directory-files bam-directory | |
nil (rx ".bam" string-end)) | |
'stringp))) | |
(list val))) | |
(insert bam)) | |
;;; 設定例 | |
(add-hook-fn 'cwl-mode-hook | |
(local-set-key (kbd "C-i d") 'insert-docker-image) | |
(local-set-key (kbd "C-i c") 'insert-docker-image) | |
(local-set-key (kbd "C-i b") 'insert-docker-image)) | |
(defun cwl-current-pos (buffer pos) | |
(interactive | |
(list (current-buffer) (point))) | |
(save-excursion | |
(goto-char pos) | |
(let ((lst nil) | |
(nindents 1) | |
(regex (rx line-start | |
(group (zero-or-more blank)) | |
(group (one-or-more (not blank))) | |
(zero-or-more blank) ":"))) | |
(while (and (> nindents 0) | |
(search-backward-regexp regex nil t)) | |
(let ((blanks (match-string-no-properties 1)) | |
(field (match-string-no-properties 2))) | |
(add-to-list 'lst field) | |
(setq nindents (if blanks (length blanks) 0)) | |
(setq regex | |
(unless (zerop nindents) | |
(eval | |
`(rx line-start | |
(group (repeat 0 ,(1- nindents) blank)) | |
(group (one-or-more (not blank))) | |
(zero-or-more blank) ":")))))) | |
lst))) | |
(defconst cwl-versions | |
'("draft-2" | |
"draft-3.dev1" "draft-3.dev2" "draft-3.dev3" "draft-3.dev4" "draft-3.dev5" | |
"draft-3" | |
"draft-4.dev1" "draft-4.dev2" "draft-4.dev3" | |
"v1.0.dev4" | |
"v1.0")) | |
(defun insert-cwl-version (ver) | |
(interactive | |
(let* ((val (completing-read "version: " cwl-versions 'stringp))) | |
(list val))) | |
(insert ver)) | |
(defun cwl-insert () | |
(interactive) | |
(pcase (cwl-current-pos (current-buffer) (point)) | |
((app (lambda (x) (car (last x))) "cwlVersion") | |
(call-interactively 'insert-cwl-version)) | |
((app (lambda (x) (car (last x))) "dockerPull") | |
(call-interactively 'insert-docker-image)) | |
(t (message "未サポート!")))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment