-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjira.el
90 lines (80 loc) · 2.77 KB
/
jira.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
;;; jira.el -*- lexical-binding: t; -*-
;;; package --- Summary
;;; Commentary:
;;; Functions which help use emacs even when you need to create stupid jira tasks via org files.
;;;
;;; Code:
(require 'dash)
(require 'subr-x)
(require 'text-util)
(defcustom jira-tasks-dir "~/tmp/"
"Dir where change log files are stored."
:group 'jira
:type 'string)
(defun jira-create-new-task (title)
"Create template file for tasks."
(interactive "sEnter title: \n")
(setq title (string-replace "/" "&" title))
(find-file (concat jira-tasks-dir title ".org"))
(insert (concat "#+title: " title "\n\n"))
(insert "_Легенда:_\n\n_Что сделать?_"))
(defun jira--special-org-chars-convert ()
"Create list of pattern to replace of special org symbols.
Returns list of pair pattern to replace."
(->> (list "_" "+" "/" "_")
(-partition 2)
(-map (lambda (coll)
(list
(concat "^" (car coll)) (last coll)
(concat "\s" (car coll)) (last coll)
(concat (car coll) "\s") (last coll)
(concat (car coll) "$") (last coll))))
(-flatten)
(-partition 2)))
(defun jira--org-link-to-jira-format (org-link)
"Convert org link to jira link.
ORG-LINK - link if format [[http:example][name-link]]
Return link in format [name-link|http:example]"
(let ((result))
(setq result
(->
(split-string (string-replace "]]" "" (string-replace "[[" "" org-link)) "\\]\\[")
(reverse)
(string-join "|")))
(concat "\[" result "\]")))
(defun jira--org-links-convert ()
"Convert org links to jira links."
(goto-char (point-min))
(let ((pattern "\\[\\[\\(.+\\)\\]\\]")
(start)
(end)
(result))
(when (re-search-forward pattern nil t)
(goto-char (- (point) 1))
(setq end (+ (point) 1))
(search-backward "[[")
(setq start (point))
(setq result (jira--org-link-to-jira-format (buffer-substring-no-properties start end)))
(kill-region start end)
(insert result))))
(defun jira-from-org-kill ()
"Convert org to jira format."
(interactive)
(let ((copy (buffer-string))
(replace-list
(->> (jira--special-org-chars-convert)
(cons (list "^#\\+title\\(.+\\)$" ""))
(cons (list "\\(\s+\\)?#\\+begin\\(.+\\)$" "{code:java}"))
(cons (list "\\(\s+\\)?#\\+end\\(.+\\)$" "{code}"))
(cons (list "^*+" "")))))
(kill-new
(with-temp-buffer
(insert copy)
(-each replace-list (apply-partially 'apply 'text-util-replace-in-whole-buffer))
(jira--org-links-convert)
(goto-char (point-min))
(while (= ?\n (char-after (point)))
(delete-char 1))
(buffer-string)))))
(provide 'jira)
;;; jira.el