每当我在打开的python文件的缓冲区中并按RET
时,它将进入下一行并通过16
(!)空格缩进。我不知道它是如何在内部得到这个数字的,但是每当发生这种情况时,我不能简单地按backspace
多次撤销无意义。相反,我得到一个错误,当我按空格键:emacs Python文件退格不起作用
python-indent-calculate-indentation: Wrong type argument: integer-or-marker-p, tab-width [x times]
但我不希望任何压痕计算在所有的,我想简单的光标之前删除字符发生......
所以我添加下面我.emacs
配置文件,希望它可以禁用按backspace
调用的任何特殊操作:
(global-unset-key [?\C-h])
(global-set-key [?\C-h] 'delete-backward-char)
然而,这并没有帮助。
我有更多的选项卡相关的设定在我.emacs
配置文件:
;; ################
;; # TAB SETTINGS #
;; ################
;; set default tab char's display width to 4 spaces
(setq-default tab-width 4) ; emacs 23.1, 24.2, default to 8
(setq-default indent-tabs-mode t)
(setq-default tab-stop-list (number-sequence 4 200 4))
(setq-default tab-width 4)
(setq-default python-indent 'tab-width)
(setq-default python-indent-offset 'tab-width)
(setq-default python-indent-levels (number-sequence 4 200 4))
(setq-default python-indent-guess-indent-offset nil)
(defvaralias 'c-indent-level 'tab-width)
(defvaralias 'c-basic-offset 'tab-width)
(defvaralias 'sgml-indent-level 'tab-width)
(defvaralias 'sgml-basic-offset 'tab-width)
这里是我的完整的配置文件,以防它需要:
;; deactivate version control integration, so that emacs starts up faster
(setq vc-handled-backends())
(setq-default vc-handled-backends nil)
(eval-after-load "vc" '(remove-hook 'find-file-hooks 'vc-find-file-hook))
;; Installation of el-get
(add-to-list 'load-path "~/.emacs.d/el-get/el-get")
(unless (require 'el-get nil 'noerror)
(with-current-buffer
(url-retrieve-synchronously "https://raw.githubusercontent.com/dimitri/el-get/master/el-get-install.el")
(goto-char (point-max))
(eval-print-last-sexp)))
(add-to-list 'el-get-recipe-path "~/.emacs.d/el-get-user/recipes")
(el-get 'sync)
;; enable company mode, always
(add-hook 'after-init-hook 'global-company-mode)
;; COMPANY SETTINGS
(setq-default company-idle-delay 0.1)
(setq-default scroll-preserve-screen-position t) ;; go back to line with the cursor after scrolling, if that line is on the screen again
;; other stuff
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(ansi-color-names-vector ["#212526" "#ff4b4b" "#b4fa70" "#fce94f" "#729fcf" "#ad7fa8" "#8cc4ff" "#eeeeec"])
'(custom-enabled-themes (quote (seti)))
'(custom-safe-themes (quote ("94ba29363bfb7e06105f68d72b268f85981f7fba2ddef89331660033101eb5e5" default)))
'(python-shell-buffer-name "Python Console")
'(show-paren-mode t)
'(tab-width 4))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(cursor ((t (:background "gold" :foreground "#151718"))))
'(show-paren-match ((t (:background "#000000" :foreground "spring green" :underline nil :weight ultra-bold))))
'(show-paren-mismatch ((t (:underline (:color "#CE4045" :style wave))))))
;; MELPA
(require 'package) ;; You might already have this line
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/"))
(add-to-list 'package-archives '("melpa-stable" . "https://melpa.org/packages/"))
(when (< emacs-major-version 24)
;; For important compatibility libraries like cl-lib
(add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/")))
(package-initialize) ;; You might already have this line
; SAVE SESSIONS - save sessions to restore buffers on next startup
(desktop-save-mode 1)
;; remember cursor position in file
(require 'saveplace)
(setq-default save-place t)
; load theme on startup
(add-hook 'emacs-startup-hook (load-theme 'seti))
;; turn on highlighting current line
(global-hl-line-mode 1)
(set-face-background 'hl-line "#303030")
(set-face-foreground 'highlight nil) ;; To keep syntax highlighting in the current line
;; highlight matching parenthesis
(show-paren-mode 1)
(setq-default show-paren-delay 0) ;; 0 delay
(setq-default show-paren-style 'parenthesis) ;;'parenthesis is another possible value, only highlighting the brackets
;; ################
;; # TAB SETTINGS #
;; ################
;; set default tab char's display width to 4 spaces
(setq-default tab-width 4) ; emacs 23.1, 24.2, default to 8
(setq-default indent-tabs-mode t)
(setq-default tab-stop-list (number-sequence 4 200 4))
(setq-default tab-width 4)
(setq-default python-indent 'tab-width)
(setq-default python-indent-offset 'tab-width)
(setq-default python-indent-levels (number-sequence 4 200 4))
(setq-default python-indent-guess-indent-offset nil)
(defvaralias 'c-indent-level 'tab-width)
(defvaralias 'c-basic-offset 'tab-width)
(defvaralias 'sgml-indent-level 'tab-width)
(defvaralias 'sgml-basic-offset 'tab-width)
(add-hook 'python-mode-hook
(lambda()
(setq indent-line-function 'insert-tab)
(setq-default indent-tabs-mode t)
(setq-default tab-width 4)
(setq-default python-indent 'tab-width)
(setq-default python-indent-offset 'tab-width)
(setq-default python-indent-levels (number-sequence 4 200 4))
(setq-default python-indent-guess-indent-offset nil)
))
;; FONT SETTINGS
(set-default-font "Ubuntu Mono 11")
;; SCROLL SPEED
(setq-default mouse-wheel-scroll-amount '(2 ((shift) . 2))) ;; two lines at a time
(setq-default mouse-wheel-progressive-speed nil) ;; don't accelerate scrolling
(setq-default mouse-wheel-follow-mouse 't) ;; scroll window under mouse
(setq-default scroll-step 2) ;; keyboard scroll one line at a time
;; case-insensitive minibuffer completion
(setq read-buffer-completion-ignore-case t)
(setq read-file-name-completion-ignore-case t)
;; LINE NUMBERS
(require 'linum)
(global-linum-mode t)
;; DELETE SELECTED TEXT WHEN TYPING
(delete-selection-mode 1)
;; NEO TREE VIEW
(add-to-list 'load-path "/home/xiaolong/.emacs.d/elpa/neotree-20160306.730/neotree.el")
(require 'neotree)
(global-set-key [f8] 'neotree-toggle)
(setq neo-smart-open t)
;; AUTO-COMPLETE
(ac-config-default)
(setq ac-delay 0.25)
(define-key ac-completing-map (kbd "RET") 'ac-stop)
;; #########################
;; # SELF DEFINED FUNCTION #
;; #########################
;; DEFINE A FUNCTION FOR DUPLICATING A LINE
(defun duplicate-line()
(interactive)
(move-beginning-of-line 1)
(kill-line)
(yank)
(newline)
(yank)
)
;; ORG MODE SHIFT SELECT
(setq-default org-support-shift-select t)
;; INDENT/UNINDENT REGION
(defun my-indent-region (N)
(interactive "p")
(if (use-region-p)
(progn (indent-rigidly (region-beginning) (region-end) (* N 4))
(setq deactivate-mark nil))
(self-insert-command N)))
(defun my-unindent-region (N)
(interactive "p")
(if (use-region-p)
(progn (indent-rigidly (region-beginning) (region-end) (* N -4))
(setq deactivate-mark nil))
(self-insert-command N)))
;; ### Hoooks for Haskell ###
(add-hook 'haskell-mode-hook 'turn-on-haskell-doc-mode)
(add-hook 'haskell-mode-hook 'turn-on-haskell-indentation)
;; ### Function for commenting and uncommenting lines ###
(defun comment-or-uncomment-line-or-region()
"Comments or uncomments the current line or region."
(interactive)
(if (region-active-p)
(comment-or-uncomment-region (region-beginning) (region-end))
(comment-or-uncomment-region (line-beginning-position) (line-end-position))
)
)
;; ###################
;; # KEY DEFINITIONS #
;; ###################
(global-set-key (kbd "RET") nil)
(define-key global-map (kbd "RET") 'newline-and-indent)
(define-key global-map (kbd "<C-return>") 'newline)
(define-key global-map (kbd "C-b") 'elpy-goto-definition)
(global-set-key (kbd "<C-mouse-5>") (lambda() (interactive) (text-scale-decrease 1)))
(global-set-key (kbd "<C-mouse-4>") (lambda() (interactive) (text-scale-increase 1)))
(global-set-key [C-kp-add] 'text-scale-increase)
(global-set-key [C-kp-subtract] 'text-scale-decrease)
(global-set-key (kbd "<dead-circumflex>") "^")
(global-set-key (kbd "<S-dead-grave>") "`")
(global-set-key (kbd "<dead-acute>") "´")
(global-set-key (kbd "<C-tab>") 'company-complete-common)
; (global-set-key (kbd "C-SPC") 'jedi:complete)
(require 'multiple-cursors)
(global-set-key (kbd "C-S-c C-S-c") 'mc/edit-lines)
(global-set-key (kbd "C-n") 'set-mark-command)
(global-set-key (kbd "C-d") 'duplicate-line)
(global-set-key (kbd "C->") 'my-indent-region)
(global-set-key (kbd "C-<") 'my-unindent-region)
;;(global-set-key (kbd "TAB") 'self-insert-command)
;;(keyboard-translate (kbd "<backtab>") (kbd "C-u -4 C-x TAB"))
(global-set-key [f8] nil)
(global-set-key [f8] 'neotree-toggle)
(global-set-key (kbd "C-M-SPC") nil)
(global-set-key (kbd "<C-kp-divide>") 'comment-or-uncomment-line-or-region) ;; ### comment and uncomment lines
(global-unset-key [?\C-h]) ; this is for the backspace key
(global-set-key [?\C-h] 'delete-backward-char) ; this is for the backspace key
总之,我简单希望退格键可以像在其他编辑器一样工作:
- 删除curso之前的字符[R
- 删除光标之前选择
- 在所有类型的文件/模式
- 没有别的,无压痕计算或任何
我在一个Fedora 22
运行的emacsGNU Emacs 24.5.1
如何在emacs中实现这一点?
该问题是否发生在你(emacs的-q'')不使用你的配置?你需要找到你的配置的一部分,使其行为奇怪。关于我的头,你可能希望'(setq-default python-indent-offset tab-width)'(带'tab-width'不加引号)和其他'setq'类似(这是'整数或标记-p错误)。将'python-indent-guess-indent-offset'设置为'nil'并不符合你的想法,因为它被用作函数。 – jpkotta
@jpkotta感谢您的帮助。在我读到的另一个答案中,'nil'意味着取消对偏移量的猜测。似乎这是错误的。我现在将其设置为“4”,并突然退格键按预期工作。唯一的问题是,一个标签仍然显示为“8”宽而不是“4”,这对我来说过于宽泛。 – Zelphir
啊,'python-indent-guess-indent-offset'既是一个函数也是一个变量;我应该仔细看看。 – jpkotta