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

Commitf8ccef3

Browse files
Merge branch 'edit-config'
2 parentsfc1cf63 +4343132 commitf8ccef3

File tree

6 files changed

+41
-2
lines changed

6 files changed

+41
-2
lines changed

‎bpython/config.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def loadini(struct, configfile):
6969
'down_one_line':'C-n',
7070
'exit':'',
7171
'external_editor':'F7',
72+
'edit_config':'F3',
7273
'edit_current_block':'C-x',
7374
'help':'F1',
7475
'last_output':'F9',
@@ -99,6 +100,8 @@ def loadini(struct, configfile):
99100
"%s\n"%default_config_path())
100101
sys.exit(1)
101102

103+
struct.config_path=config_path
104+
102105
struct.dedent_after=config.getint('general','dedent_after')
103106
struct.tab_length=config.getint('general','tab_length')
104107
struct.auto_display_list=config.getboolean('general',
@@ -131,6 +134,7 @@ def loadini(struct, configfile):
131134
struct.delete_key=config.get('keyboard','delete')
132135
struct.exit_key=config.get('keyboard','exit')
133136
struct.last_output_key=config.get('keyboard','last_output')
137+
struct.edit_config_key=config.get('keyboard','edit_config')
134138
struct.edit_current_block_key=config.get('keyboard','edit_current_block')
135139
struct.external_editor_key=config.get('keyboard','external_editor')
136140
struct.help_key=config.get('keyboard','help')

‎bpython/curtsiesfrontend/repl.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,8 @@ def process_key_event(self, e):
497497
greenlet.greenlet(self.pastebin).switch()
498498
elifeinkey_dispatch[self.config.external_editor_key]:
499499
self.send_session_to_external_editor()
500+
elifeinkey_dispatch[self.config.edit_config_key]:
501+
greenlet.greenlet(self.edit_config).switch()
500502
#TODO add PAD keys hack as in bpython.cli
501503
elifeinkey_dispatch[self.config.edit_current_block_key]:
502504
self.send_current_block_to_external_editor()

‎bpython/repl.py‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,36 @@ def send_to_external_editor(self, text, filename=None):
10221022
else:
10231023
returntext
10241024

1025+
defopen_in_external_editor(self,filename):
1026+
editor_args=shlex.split(self.config.editor)
1027+
ifsubprocess.call(editor_args+ [filename])==0:
1028+
returnTrue
1029+
returnFalse
1030+
1031+
defedit_config(self):
1032+
ifnot (os.path.isfile(self.config.config_path)):
1033+
ifself.interact.confirm(_("Config file does not exist - create new from default? (y/N)")):
1034+
try:
1035+
bpython_dir,script_name=os.path.split(__file__)
1036+
withopen(os.path.join(bpython_dir,"sample-config"))asf:
1037+
default_config=f.read()
1038+
1039+
containing_dir=os.path.dirname(os.path.abspath(self.config.config_path))
1040+
ifnotos.path.exists(containing_dir):
1041+
os.makedirs(containing_dir)
1042+
withopen(self.config.config_path,'w')asf:
1043+
f.write(default_config)
1044+
except (IOError,OSError)ase:
1045+
self.interact.notify('error creating file: %r'%e)
1046+
returnFalse
1047+
else:
1048+
returnFalse
1049+
1050+
ifself.open_in_external_editor(self.config.config_path):
1051+
self.interact.notify('bpython config file edited. Restart bpython for changes to take effect.')
1052+
else:
1053+
self.interact.notify('error editing config file')
1054+
10251055

10261056
defnext_indentation(line,tab_length):
10271057
"""Given a code line, return the indentation of the next line."""

‎sample-config‎renamed to ‎bpython/sample-config‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
# By default bpython will look for $XDG_CONFIG_HOME/bpython/config
44
# ($XDG_CONFIG_HOME defaults to ~/.config) or you can specify a file with the
55
# --config option on the command line
6+
#
7+
# see http://docs.bpython-interpreter.org/configuration.html
8+
# for all configurable options
69

710
# General section tag
811
[general]

‎doc/sphinx/source/configuration-options.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ Valid keys are:
159159

160160
pastebin
161161
^^^^^^^^
162-
Default:<F8>
162+
Default:F8
163163

164164
last_output
165165
^^^^^^^^^^^

‎setup.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def initialize_options(self):
184184
packages=packages,
185185
data_files=data_files,
186186
package_data= {
187-
'bpython': ['logo.png'],
187+
'bpython': ['logo.png','sample-config'],
188188
'bpython.translations':mo_files,
189189
'bpython.test': ['test.config','test.theme']
190190
},

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp