Это было изящное упражнение в разочаровании. По некоторым причинам мои буферы python -mode / elpy всегда имеют intent-tabs-mode nil
. Я использую python -режим 6.2.3, elpy 1.32.0 и emacs 25.2.2. Мой файл .emacs содержит:
;; =============================================================================
;; Trying to get indentation to be tabs of width 4 spaces in Python is a real
;; pain. For some unknown reason, unlike EVERY other progmode file in the distro
;; python.el contains this gem:
;;
;; 5480: (set (make-local-variable 'tab-width) 8)
;;
;; which clobbers any defaults you might have, no questoins asked. It also has
;; this wonderful nugget:
;;
;; 5481: (set (make-local-variable 'indent-tabs-mode) nil)
;;
;; Because someone wants to force using spaces (so wby bother forcing
;; tab-width?)
;; -----------------------------------------------------------------------------
;; Do this first. Because of the above, if you don't python.el will clobber
;; your attempts to customize this stuff.
(load "python-mode")
;; Now follow the instructions sprinked all over the Interwebs by the thousands
;; of people frustrated by the above clobbering.
(add-hook 'python-mode-hook
;; Don't forget lambda(), God forbid
(lambda ()
;; Now set the tab-width you really want here and cross your fingers
(setq tab-width 4)
;; And tell python-mode to use tabs. I know lots of folks hate on
;; tabs, but whatever.
(setq indent-tabs-mode t)
;; If you want to make sure you don't have trailing whitespaces
;; at the end of line, uncomment this.
;;(add-to-list 'write-file-functions 'delete-trailing-whitespace)
)
)
Но indent-tabs-mode
остается nil
. Только в режиме python, конечно. Из describe-variable
из буфера python -mode / elpy:
indent-tabs-mode is a variable defined in ‘C source code’.
Its value is nil
Original value was t
Local in buffer config; global value is t
Automatically becomes buffer-local when set.
This variable is safe as a file local variable if its value
satisfies the predicate ‘booleanp’.
Documentation:
Indentation can insert tabs if this is non-nil.
You can customize this variable.
Используемая версия python -mode.el содержит следующие [строки 955-964]:
"Python-mode starts `indent-tabs-mode' with the value specified here, default is nil. "
:type 'boolean
:tag "py-indent-tabs-mode"
:group 'python-mode)
[строки 5159-5165]
["indent-tabs-mode"
(setq indent-tabs-mode
(not indent-tabs-mode))
:help "Indentation can insert tabs if this is non-nil.
Use `M-x customize-variable' to set it permanently"
:style toggle :selected indent-tabs-mode]
[строки 6787-6820]
(defun py-toggle-indent-tabs-mode ()
"Toggle `indent-tabs-mode'.
Returns value of `indent-tabs-mode' switched to. "
(interactive)
(when
(setq indent-tabs-mode (not indent-tabs-mode))
(setq tab-width py-indent-offset))
(when (and py-verbose-p (called-interactively-p 'any)) (message "indent-tabs-mode %s py-indent-offset %s" indent-tabs-mode py-indent-offset))
indent-tabs-mode)
(defun py-indent-tabs-mode (arg &optional iact)
"With positive ARG switch `indent-tabs-mode' on.
With negative ARG switch `indent-tabs-mode' off.
Returns value of `indent-tabs-mode' switched to. "
(interactive "p")
(if (< 0 arg)
(progn
(setq indent-tabs-mode t)
(setq tab-width py-indent-offset))
(setq indent-tabs-mode nil))
(when (and py-verbose-p (or iact (called-interactively-p 'any))) (message "indent-tabs-mode %s py-indent-offset %s" indent-tabs-mode py-indent-offset))
indent-tabs-mode)
(defun py-indent-tabs-mode-on (arg)
"Switch `indent-tabs-mode' on. "
(interactive "p")
(py-indent-tabs-mode (abs arg)(called-interactively-p 'any)))
(defun py-indent-tabs-mode-off (arg)
"Switch `indent-tabs-mode' off. "
(interactive "p")
(py-indent-tabs-mode (- (abs arg))(called-interactively-p 'any)))
[строки 22259-22266]
;; unconditional Hooks
;; (orgstruct-mode 1)
(add-hook 'python-mode-hook
(lambda ()
(setq imenu-create-index-function py--imenu-create-index-function)
(setq indent-tabs-mode py-indent-tabs-mode)))
(remove-hook 'python-mode-hook 'python-setup-brm)
И снова (почти идентично сверху) [строки 25021-25033]:
["indent-tabs-mode"
(setq indent-tabs-mode
(not indent-tabs-mode))
:help "Indentation can insert tabs if this is non-nil.
Use `M-x customize-variable' to set it permanently"
:style toggle :selected indent-tabs-mode]
["Tab indent"
(setq py-tab-indent
(not py-tab-indent))
:help "Non-nil means TAB in Python mode calls `py-indent-line'.Use `M-x customize-variable' to set it permanently"
:style toggle :selected py-tab-indent]
Я установил каждую версию любого определения, которое смог найти в любом файле * .el indent-tabs-mode
, на t
и ничего не работает.