Измените эту строку:
t = timeit.Timer("foo()")
К этому:
t = timeit.Timer("foo()", "from __main__ import foo")
Выезд ссылка Вы обеспечили в самой нижней части.
Для предоставления timeit доступа модуля к функциям Вы определяете, можно передать параметр установки, который содержит оператора импорта:
я просто протестировал его на своей машине, и это работало с изменениями.
Чтобы развернуть Сета ответ , я бы сделал следующее:
(defadvice switch-to-buffer (before save-buffer-now activate)
(when buffer-file-name (save-buffer)))
(defadvice other-window (before other-window-now activate)
(when buffer-file-name (save-buffer)))
(defadvice other-frame (before other-frame-now activate)
(when buffer-file-name (save-buffer)))
Проверка для имя-файла-буфера
позволяет избежать сохранения буферов без файлов. Вам нужно выяснить все точки входа, которые вы используете для переключения буферов, которые вам нужны (я бы также посоветовал other-window
).
I'm kind of new to emacs lisp myself but this works in my testing:
(defadvice switch-to-buffer (before save-buffer-now)
(save-buffer))
(ad-activate 'switch-to-buffer)
It's kind of annoying though because it's called after EVERY buffer (like scratch). So, consider this answer a hint.
When you want to disable it, you'll need to call:
(ad-disable-advice 'switch-to-buffer 'before 'save-buffer-now)
(ad-activate 'switch-to-buffer)
A couple of ideas.
First, if you find yourself invoking a command like save with a sufficiently high frequency, you might consider a shorter key binding for the command. For example, I also found myself having the same "twitch," so now I use f2
instead of C-x C-s
for saving edits.
The function that I bind to f2
saves every unsaved buffer unconditionally. You might find it useful:
(defun force-save-all ()
"Unconditionally saves all unsaved buffers."
(interactive)
(save-some-buffers t))
(global-set-key [f2] 'force-save-all)
Now, on to the main issue. You could try something like this (notice that force-save-all
is called):
(defun my-switch-to-buffer (buffer)
(interactive (list (read-buffer "Switch to buffer: " (cadr buffer-name-history) nil)))
(force-save-all)
(switch-to-buffer buffer))
(global-set-key "\C-xb" 'my-switch-to-buffer)
Of course, you could also bind the switch buffer functionality to another key, like a function key, so that it's a one press operation.
I thought that @seth had a great idea about using advice, but I noticed that the ELisp manual suggests that advice not be used for key bindings. I'm not quite sure why this is the case, but that's what the manual suggests FYI.