@@ -49,14 +49,14 @@ def search_in_org(file, note_id):
4949 data = open (file , "r" ).read ()
5050 except Exception as e :
5151 print ("Openfile: open: %s" % str (e ))
52- return None
52+ return ()
5353
5454 res = config ["note_match" ].format (note_id = note_id )
5555 found = re .compile (res , flags = re .MULTILINE ).search (data )
5656 if found :
57- return (found .start (0 ), found .end (0 ))
57+ return (found .group ( 1 ), found . start (0 ), found .end (0 ))
5858
59- return None
59+ return ()
6060
6161
6262def lru_file_cache (func ):
@@ -89,6 +89,8 @@ def find_anki_note(note_id, org_dir='~/org'):
8989 search_path = os .path .expanduser (org_dir )
9090 use_ripgrep = config ["use_ripgrep" ]
9191 rg_opts = config ["ripgrep_opts" ].split (" " )
92+
93+ note_type = "ANKI_NOTE_ID"
9294 if use_ripgrep and shutil .which (rg_opts [0 ]):
9395 pat = config ["note_match" ].format (note_id = "(.+?)" )
9496 rg_ret = subprocess .run (rg_opts .split (' ' ) + ['--json' , pat , f'"{ search_path } "' ], stdout = subprocess .PIPE ).stdout .decode ('utf-8' )
@@ -105,7 +107,14 @@ def find_anki_note(note_id, org_dir='~/org'):
105107 abs_offset = js_line ["data" ]["absolute_offset" ]
106108 sub_start = js_line ["data" ]["submatches" ][0 ]["start" ]
107109 sub_end = js_line ["data" ]["submatches" ][0 ]["end" ]
108- return org_name , (abs_offset + sub_start , abs_offset + sub_end )
110+ match_text = js_line ["data" ]["submatches" ][0 ]["match" ]
111+
112+ if match_text :
113+ found_note_type = re .findall (pat , match_text ["text" ])
114+ if found_note_type :
115+ note_type = found_note_type [0 ]
116+
117+ return org_name , (note_type , abs_offset + sub_start , abs_offset + sub_end )
109118 else :
110119 for org_name in glob (os .path .join (search_path , '**/*.org' ), recursive = True ):
111120 docs = search_in_org (org_name , note_id )
@@ -120,8 +129,10 @@ def open_anki_note(note_id):
120129 org_file , found_note = find_anki_note (note_id , org_dir )
121130 # print('debug:', org_file, found_note)
122131 if org_file and found_note :
123- char_pos = found_note [0 ]
124- os .system (config ["exec" ].format (org_file = org_file , char_pos = char_pos ))
132+ note_type = found_note [0 ]
133+ char_pos_begin = found_note [1 ]
134+ char_pos_end = found_note [2 ]
135+ os .system (config ["exec" ].format (org_file = org_file , note_type = note_type , char_pos_begin = char_pos_begin , char_pos_end = char_pos_end ))
125136 found = True
126137 break
127138
0 commit comments