|
2 | 2 |
|
3 | 3 | # %% auto 0 |
4 | 4 | __all__= ['Placements','empty','find_var','call_endp','find_dname','find_msg_id','curr_dialog','find_msgs','msg_idx', |
5 | | -'read_msg','add_html','run_msg','add_msg','del_msg','update_msg','url2note','ast_py','ast_grep', |
6 | | -'load_gist','gist_file','import_string','is_usable_tool','mk_toollist','import_gist','tool_info', |
7 | | -'fc_tool_info','asdict'] |
| 5 | +'read_msg','msg_insert_line','msg_str_replace','msg_strs_replace','msg_replace_lines','add_html', |
| 6 | +'run_msg','add_msg','del_msg','update_msg','url2note','ast_py','ast_grep','load_gist','gist_file', |
| 7 | +'import_string','is_usable_tool','mk_toollist','import_gist','tool_info','fc_tool_info','asdict'] |
8 | 8 |
|
9 | 9 | # %% ../nbs/00_core.ipynb |
10 | 10 | importjson,importlib,linecache |
@@ -90,14 +90,55 @@ def msg_idx( |
90 | 90 |
|
91 | 91 | # %% ../nbs/00_core.ipynb |
92 | 92 | defread_msg( |
93 | | -n:int=-1,# Messageindex (if relative, +ve is downwards) |
94 | | -msgid=None,# Message id to find (defaults to current message) |
95 | | -relative:bool=True,# Is `n` relativetocurrent message (True) or absolute (False)? |
| 93 | +msgid:str,# Messageid to find (defaults to current message) |
| 94 | +view_range:list[int,int]=None,# Optional 1-indexed (start, end) line range for files, end=-1 for EOF |
| 95 | +nums:bool=False,# Whethertoshow line numbers |
96 | 96 | dname:str=''# Running dialog to get info for; defaults to current dialog |
97 | 97 | ): |
98 | 98 | "Get the `Message` object indexed in the current dialog." |
99 | | -ifnotmsgid:msgid=find_msg_id() |
100 | | -returncall_endp('read_msg_',dname,json=True,msgid=msgid,n=n,relative=relative)['msg'] |
| 99 | +data=dict(msgid=msgid) |
| 100 | +ifview_range:data['view_range']=view_range# None gets converted to '' so we avoid passing it to use the p.default |
| 101 | +ifnums:data['nums']=nums |
| 102 | +returncall_endp('read_msg_',dname,json=True,**data) |
| 103 | + |
| 104 | +# %% ../nbs/00_core.ipynb |
| 105 | +defmsg_insert_line( |
| 106 | +msgid:str,# Message id to find (defaults to current message) |
| 107 | +insert_line:int,# Line number where to insert (0-based indexing) |
| 108 | +new_str:str,# Text to insert at the specified line |
| 109 | +dname:str=''# Running dialog to get info for; defaults to current dialog |
| 110 | + ): |
| 111 | +"Get the `Message` object indexed in the current dialog." |
| 112 | +returncall_endp('msg_insert_line_',dname,json=True,msgid=msgid,insert_line=insert_line,new_str=new_str) |
| 113 | + |
| 114 | +# %% ../nbs/00_core.ipynb |
| 115 | +defmsg_str_replace( |
| 116 | +msgid:str,# Message id to find (defaults to current message) |
| 117 | +old_str:str,# Text to find and replace |
| 118 | +new_str:str,# Text to replace with |
| 119 | +dname:str=''# Running dialog to get info for; defaults to current dialog |
| 120 | +): |
| 121 | +"Get the `Message` object indexed in the current dialog." |
| 122 | +returncall_endp('msg_str_replace_',dname,json=True,msgid=msgid,old_str=old_str,new_str=new_str) |
| 123 | + |
| 124 | +# %% ../nbs/00_core.ipynb |
| 125 | +defmsg_strs_replace( |
| 126 | +msgid:str,# Message id to find (defaults to current message) |
| 127 | +old_strs:list[str],# List of strings to find and replace |
| 128 | +new_strs:list[str],# List of replacement strings (must match length of old_strs) |
| 129 | +dname:str=''# Running dialog to get info for; defaults to current dialog |
| 130 | +): |
| 131 | +returncall_endp('msg_strs_replace_',dname,json=True,msgid=msgid,old_strs=old_strs,new_strs=new_strs) |
| 132 | + |
| 133 | +# %% ../nbs/00_core.ipynb |
| 134 | +defmsg_replace_lines( |
| 135 | +msgid:str,# Message id to find (defaults to current message) |
| 136 | +start_line:int,# Starting line number to replace (1-based indexing) |
| 137 | +end_line:int,# Ending line number to replace (1-based indexing, inclusive) |
| 138 | +new_content:str,# New content to replace the specified lines |
| 139 | +dname:str=''# Running dialog to get info for; defaults to current dialog |
| 140 | +): |
| 141 | +returncall_endp('msg_replace_lines_',dname,json=True,msgid=msgid,start_line=start_line,end_line=end_line,new_content=new_content) |
101 | 142 |
|
102 | 143 | # %% ../nbs/00_core.ipynb |
103 | 144 | defadd_html( |
|