Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf994abb

Browse files
committed
text edit tools for msgs
1 parentfd133e0 commitf994abb

File tree

3 files changed

+450
-48
lines changed

3 files changed

+450
-48
lines changed

‎dialoghelper/_modidx.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
'dialoghelper.core.load_gist': ('core.html#load_gist','dialoghelper/core.py'),
2727
'dialoghelper.core.mk_toollist': ('core.html#mk_toollist','dialoghelper/core.py'),
2828
'dialoghelper.core.msg_idx': ('core.html#msg_idx','dialoghelper/core.py'),
29+
'dialoghelper.core.msg_insert_line': ('core.html#msg_insert_line','dialoghelper/core.py'),
30+
'dialoghelper.core.msg_replace_lines': ('core.html#msg_replace_lines','dialoghelper/core.py'),
31+
'dialoghelper.core.msg_str_replace': ('core.html#msg_str_replace','dialoghelper/core.py'),
32+
'dialoghelper.core.msg_strs_replace': ('core.html#msg_strs_replace','dialoghelper/core.py'),
2933
'dialoghelper.core.read_msg': ('core.html#read_msg','dialoghelper/core.py'),
3034
'dialoghelper.core.run_msg': ('core.html#run_msg','dialoghelper/core.py'),
3135
'dialoghelper.core.tool_info': ('core.html#tool_info','dialoghelper/core.py'),

‎dialoghelper/core.py‎

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
# %% auto 0
44
__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']
88

99
# %% ../nbs/00_core.ipynb
1010
importjson,importlib,linecache
@@ -90,14 +90,55 @@ def msg_idx(
9090

9191
# %% ../nbs/00_core.ipynb
9292
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
9696
dname:str=''# Running dialog to get info for; defaults to current dialog
9797
):
9898
"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)
101142

102143
# %% ../nbs/00_core.ipynb
103144
defadd_html(

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp