From eddf88f818663dd821277134280ff3fe197d0739 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Wed, 10 Aug 2022 12:57:37 +0300 Subject: [PATCH 1/4] Org buffer customization settings to tail of khoj.el results buffer - Results get priority screen real estate - Allows quick speed key based traversal of results as cursor on switching to buffer is at top level heading - E.g C-x o n n o 2 jumps to entry in actual file of second result - Unlike before when it is at the #+STARTUP org buffer customization settings --- src/interface/emacs/khoj.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interface/emacs/khoj.el b/src/interface/emacs/khoj.el index a75ad4a1..fe0d7248 100644 --- a/src/interface/emacs/khoj.el +++ b/src/interface/emacs/khoj.el @@ -152,7 +152,7 @@ Use `which-key` if available, else display simple message in echo area" (replace-regexp-in-string "^[\(\) ]" "" ;; extract entries from response as single string and convert to entries - (format "#+STARTUP: showall hidestars inlineimages\n* %s\n%s" + (format "* %s\n%s\n#+STARTUP: showall hidestars inlineimages" query (mapcar (lambda (args) From a02d9db457c1c64c4ebcadfd6e7db3eeff49f0a2 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Wed, 10 Aug 2022 13:48:18 +0300 Subject: [PATCH 2/4] Test Task State Extraction in OrgNode Tests --- tests/test_orgnode.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/test_orgnode.py b/tests/test_orgnode.py index a516fe7f..186eaaec 100644 --- a/tests/test_orgnode.py +++ b/tests/test_orgnode.py @@ -37,7 +37,7 @@ def test_parse_complete_entry(tmp_path): "Test parsing of entry with all important fields" # Arrange entry = f''' -*** [#A] Heading :Tag1:TAG2:tag3: +*** DONE [#A] Heading :Tag1:TAG2:tag3: CLOSED: [1984-04-01 Sun 12:00] SCHEDULED: <1984-04-01 Sun 09:00> DEADLINE: <1984-04-01 Sun> :PROPERTIES: :ID: 123-456-789-4234-1231 @@ -56,6 +56,7 @@ Body Line 2''' # Assert assert len(entries) == 1 assert entries[0].Heading() == "Heading" + assert entries[0].Todo() == "DONE" assert entries[0].Tags() == {"Tag1", "TAG2", "tag3"} assert entries[0].Body() == "- Clocked Log 1\nBody Line 1\nBody Line 2" assert entries[0].Priority() == "A" @@ -124,7 +125,7 @@ def test_parse_multiple_entries(tmp_path): "Test parsing of multiple entries" # Arrange content = f''' -*** [#A] Heading1 :tag1: +*** FAILED [#A] Heading1 :tag1: CLOSED: [1984-04-01 Sun 12:00] SCHEDULED: <1984-04-01 Sun 09:00> DEADLINE: <1984-04-01 Sun> :PROPERTIES: :ID: 123-456-789-4234-0001 @@ -135,7 +136,7 @@ CLOCK: [1984-04-01 Sun 09:00]--[1984-04-01 Sun 12:00] => 3:00 :END: Body 1 -*** [#A] Heading2 :tag2: +*** CANCELLED [#A] Heading2 :tag2: CLOSED: [1984-04-02 Sun 12:00] SCHEDULED: <1984-04-02 Sun 09:00> DEADLINE: <1984-04-02 Sun> :PROPERTIES: :ID: 123-456-789-4234-0002 @@ -156,6 +157,7 @@ Body 2 assert len(entries) == 2 for index, entry in enumerate(entries): assert entry.Heading() == f"Heading{index+1}" + assert entry.Todo() == "FAILED" if index == 0 else "CANCELLED" assert entry.Tags() == {f"tag{index+1}"} assert entry.Body() == f"- Clocked Log {index+1}\nBody {index+1}\n\n" assert entry.Priority() == "A" From fd31d339c1fb6f14a395d24579f106c53b76b446 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Wed, 10 Aug 2022 13:48:44 +0300 Subject: [PATCH 3/4] Remove spurious space in Entries without Todo in OrgNode Entry Repr --- src/processor/org_mode/orgnode.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/processor/org_mode/orgnode.py b/src/processor/org_mode/orgnode.py index fcf5d806..151c61df 100644 --- a/src/processor/org_mode/orgnode.py +++ b/src/processor/org_mode/orgnode.py @@ -370,7 +370,9 @@ class Orgnode(object): n = '' for _ in range(0, self.level): n = n + '*' - n = n + ' ' + self.todo + ' ' + n = n + ' ' + if self.todo: + n = n + self.todo + ' ' if self.prty: n = n + '[#' + self.prty + '] ' n = n + self.headline From 150ae196607bad32e016641bac0ed6a97c0edf56 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Wed, 10 Aug 2022 18:55:37 +0300 Subject: [PATCH 4/4] Indent Timestamps, Drawers at Body Level in OrgNode Entry Representation --- src/processor/org_mode/orgnode.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/processor/org_mode/orgnode.py b/src/processor/org_mode/orgnode.py index 151c61df..39c67731 100644 --- a/src/processor/org_mode/orgnode.py +++ b/src/processor/org_mode/orgnode.py @@ -38,6 +38,8 @@ import datetime from pathlib import Path from os.path import relpath +indent_regex = re.compile(r'^\s*') + def normalize_filename(filename): file_relative_to_home = f'~/{relpath(filename, start=Path.home())}' escaped_filename = f'{file_relative_to_home}'.replace("[","\[").replace("]","\]") @@ -384,7 +386,12 @@ class Orgnode(object): n = n + closecolon n = n + "\n" + # Get body indentation from first line of body + indent = indent_regex.match(self.body).group() + # Output Closed Date, Scheduled Date, Deadline Date + if self.closed or self.scheduled or self.deadline: + n = n + indent if self.closed: n = n + f'CLOSED: [{self.closed.strftime("%Y-%m-%d %a")}] ' if self.scheduled: @@ -395,10 +402,10 @@ class Orgnode(object): n = n + '\n' # Ouput Property Drawer - n = n + ":PROPERTIES:\n" + n = n + indent + ":PROPERTIES:\n" for key, value in self.properties.items(): - n = n + f":{key}: {value}\n" - n = n + ":END:\n" + n = n + indent + f":{key}: {value}\n" + n = n + indent + ":END:\n" n = n + self.body