Skip to content

Commit

Permalink
Support links better suited for html export in org-kanban table
Browse files Browse the repository at this point in the history
Now supported are with the given priorities:
```
file:#customid
id:theid
file:heading
heading
```

if the org-kanban table is in the same file, the variants without
the file protocol are taken.

Fixes #8
  • Loading branch information
gizmomogwai committed Jun 7, 2018
1 parent 9b2bd85 commit e8e56f6
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Cask
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(source gnu)
(source melpa)

(package "org-kanban" "0.4.1" "Kanban for org-mode.")
(package "org-kanban" "0.4.5" "Kanban for org-mode.")
(package-file "org-kanban.el")

(depends-on "org")
Expand Down
40 changes: 35 additions & 5 deletions features/work-org-kanban.feature
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ Feature: Work kanban tables
* DONE b
* DONE c
:PROPERTIES:
:CUSTOM_ID: 1
:CUSTOM_ID: customid1
:ID: id1
:END:
* DONE d
:PROPERTIES:
:ID: id2
:END:
* Kanban
#+BEGIN: kanban
Expand All @@ -25,20 +30,20 @@ Feature: Work kanban tables
|------+------|
| [[a][a]] | |
| | [[b][b]] |
| | [[#1][c]] |
| | [[#customid1][c]] |
| | [[id:id2][d]] |
#+END:
"""

Scenario: Move Todo Item
When I go to line "11"
Scenario: Move Todo Items
When I go to line "16"
And I run org-kanban/shift
Then I should see:
"""
| TODO | DONE |
|------+------|
| | [[a][a]] |
| | [[b][b]] |
| | [[#1][c]] |
"""

And I press "j"
Expand Down Expand Up @@ -85,3 +90,28 @@ Feature: Work kanban tables
| [[a][a]] | |
| | [[b][b]] |
"""

Scenario: Move Todo Items by customid
When I go to line "18"
And I run org-kanban/prev
Then I should see:
"""
| TODO | DONE |
|------+------|
| [[a][a]] | |
| | [[b][b]] |
| [[#customid1][c]] | |
"""

Scenario: Move Todo Items by id
When I go to line "19"
And I run org-kanban/prev
Then I should see:
"""
| TODO | DONE |
|------+------|
| [[a][a]] | |
| | [[b][b]] |
| | [[#customid1][c]] |
| [[id:id2][d]] | |
"""
71 changes: 59 additions & 12 deletions org-kanban.el
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
;; Contributors:
;; Aldric Giacomoni <[email protected]>
;; Keywords: org-mode, org, kanban, tools
;; Package-Requires: ((dash "2.13.0") (emacs "24.4"))
;; Package-Requires: ((dash "2.13.0") (emacs "24.4") (org "9.1"))
;; Package-Version: 0.4.5
;; Homepage: http://github.com/gizmomogwai/org-kanban

Expand Down Expand Up @@ -63,7 +63,9 @@
(current-buffer)
(org-heading-components)
org-todo-keywords-1
(org-entry-get nil "CUSTOM_ID")))
(org-entry-get nil "CUSTOM_ID")
(org-entry-get nil "ID")
))

(defun org-kanban//todo-info-get-file (todo-info)
"Get the buffer from a TODO-INFO."
Expand All @@ -81,6 +83,10 @@
"Get the CUSTOM_ID from a heading TODO-INFO."
(nth 3 todo-info))

(defun org-kanban//todo-info-get-id (todo-info)
"Get the ID from a heading TODO-INFO."
(nth 4 todo-info))

(defun org-kanban//heading-get-title (heading)
"Get the title from a org-mode HEADING."
(nth 4 heading))
Expand All @@ -97,20 +103,49 @@
link-abbreviation)
heading))

(defun org-kanban//link (file heading kanban search-for multi-file custom-id)
"Create a link to FILE and HEADING if the KANBAN value is equal to SEARCH-FOR. MULTI-FILE indicates if simple links may be used. CUSTOM_ID if available. This means, that the org-kanban table links are in one of 4 forms: with or without file: and with heading as link or #custom_id."
(if (and (stringp kanban) (string-equal search-for kanban))
(defun org-kanban//link-for-custom-id (custom-id use-file file description)
"Create a link for CUSTOM-ID."
(if custom-id
(if use-file
(format "[[file:%s::#%s][%s]]" file custom-id description)
(format "[[#%s][%s]]" custom-id description))
nil))

(defun org-kanban//link-for-id (id description)
"Create a link for ID."
(if id
(format "[[id:%s][%s]]" id description)
nil))

(defun org-kanban//link-for-heading (heading use-file file description)
"Create a link for a heading."
(if heading
(if use-file
(format "[[file:%s::*%s][%s]]" file heading description)
(format "[[%s][%s]]" heading description))
(error "Illegal state")))

(defun org-kanban//link (file heading kanban search-for multi-file custom-id id)
"Create a link to FILE and HEADING if the KANBAN value is equal to SEARCH-FOR. MULTI-FILE indicates if the link must work across several files. CUSTOM_ID links are used if given. ID links are used if given. This means, that the org-kanban table links are in one of several forms:
- file:#custom-id
- #custom-id
- id:id
- file:heading
- heading
"
(if
(and (stringp kanban) (string-equal search-for kanban))
(let* (
(link-abbreviation (car org-kanban/abbreviation))
(link-max-length (cdr org-kanban/abbreviation))
(description (org-kanban//heading-to-description heading link-max-length link-abbreviation))
(heading-or-id (if custom-id (format "#%s" custom-id) heading))
(use-file (and multi-file (not (eq file (current-buffer)))))
)
(if use-file
(format "[[file:%s::%s][%s]]" file heading-or-id description)
(format "[[%s][%s]]" heading-or-id description)
)) ""))
)
(or (org-kanban//link-for-custom-id custom-id use-file file description)
(org-kanban//link-for-id id description)
(org-kanban//link-for-heading heading use-file file description)
))
""))

(defun org-kanban//todo-keywords (files mirrored)
"Get list of org todos from FILES. MIRRORED describes if keywords should be reversed."
Expand All @@ -133,7 +168,8 @@ TODO-KEYWORDS are all the current org todos. MULTI-FILE indicates, if simple fil
(title (org-kanban//heading-get-title heading))
(kanban (org-kanban//heading-get-todo-keyword heading))
(custom-id (org-kanban//todo-info-get-custom-id todo-info))
(row-entries (-map (lambda(i) (org-kanban//link file title i kanban multi-file custom-id)) todo-keywords))
(id (org-kanban//todo-info-get-id todo-info))
(row-entries (-map (lambda(i) (org-kanban//link file title i kanban multi-file custom-id id)) todo-keywords))
(row (string-join row-entries "|")))
(format "|%s|" row)))

Expand Down Expand Up @@ -166,6 +202,7 @@ TODO-KEYWORDS are all the current org todos. MULTI-FILE indicates, if simple fil

(defun org-kanban//find-by-custom-id (line)
""
(message "find by custom id %s" line)
(let* (
(pattern "\\[\\[#\\(.*\\)\\]\\[.*\\]")
(match (string-match pattern line))
Expand All @@ -182,6 +219,15 @@ TODO-KEYWORDS are all the current org todos. MULTI-FILE indicates, if simple fil
(entry (and heading (org-find-exact-headline-in-buffer heading))))
(if entry (list (buffer-file-name) entry) nil)))

(defun org-kanban//find-by-id (line)
""
(let* (
(pattern "\\[\\[id:\\(.*\\)\\]\\[.*\\]")
(match (string-match pattern line))
(id (and match (match-string 1 line)))
(entry (and id (org-find-entry-with-id id))))
(if entry (list (buffer-file-name) entry) nil)))

(defun org-kanban//find ()
"Search for a todo matching to the current kanban table row.
Return file and marker."
Expand All @@ -196,6 +242,7 @@ Return file and marker."
(or (org-kanban//find-by-file-and-custom-id line)
(org-kanban//find-by-file-and-heading line)
(org-kanban//find-by-custom-id line)
(org-kanban//find-by-id line)
(org-kanban//find-by-heading line))))

(defun org-kanban/next ()
Expand Down
22 changes: 20 additions & 2 deletions rakefile.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@

task :default => :test

desc 'prepare'
task :prepare do
sh "cask install"
end

def get_match(content, regexp)
match = regexp.match(content)
if !match
raise 'cannot match'
end
return match[1]
end

desc 'test'
task :test do
# sh "cask exec ecukes --verbose --debug --reporter magnars"
sh "cask exec ecukes --reporter magnars --quiet"
org_kanban_melpa_version = get_match(File.read('org-kanban.el', encoding: 'UTF-8'), Regexp.new('Package-Version: (.*)'))
org_kanban_elisp_version = get_match(File.read('org-kanban.el', encoding: 'UTF-8'), Regexp.new('\\(message "org-kanban (.*)"\\)\\)'))
cask_version = get_match(File.read('Cask', encoding: 'UTF-8'), Regexp.new('\\(package "org-kanban" "(.*)" "Kanban for org-mode."\\)'))
if org_kanban_melpa_version != org_kanban_elisp_version or org_kanban_elisp_version != cask_version
puts "org_kanban_melpa_version: #{org_kanban_melpa_version}"
puts "org_kanban_elisp_version: #{org_kanban_elisp_version}"
puts "org_kanban_cask_version: #{cask_version}"
raise 'versions inconsistent'
end
sh "cask exec ecukes --verbose --debug --reporter magnars"
# sh "cask exec ecukes --reporter magnars --quiet"
end
2 changes: 2 additions & 0 deletions todo.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Todos
** TODO write test for multi file org kanban table

0 comments on commit e8e56f6

Please sign in to comment.