首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >emacs Python文件备份空间不工作

emacs Python文件备份空间不工作
EN

Stack Overflow用户
提问于 2016-05-30 19:11:02
回答 1查看 582关注 0票数 1

每当我在打开的python文件的缓冲区中并按RET时,它将转到16 (!)的下一行和缩进处。空格。我不知道它如何在内部得到这个数字,但每当发生这种情况时,我不能简单地多次按backspace来撤消非意义。相反,当我按backspace时会得到一个错误:

代码语言:javascript
复制
python-indent-calculate-indentation: Wrong type argument: integer-or-marker-p, tab-width [x times]

但是我不希望任何缩进计算发生,我只是想在光标之前删除字符.

因此,我将以下内容添加到我的.emacs配置文件中,希望它能够禁用通过按backspace调用的任何特殊操作

代码语言:javascript
复制
(global-unset-key [?\C-h])
(global-set-key [?\C-h] 'delete-backward-char)

然而,这并没有帮助。

在我的.emacs配置文件中还有一些与选项卡相关的设置:

代码语言:javascript
复制
;; ################
;; # 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)

这是我的完整配置文件,以防需要它:

代码语言:javascript
复制
;; 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

总之,我只想让backspace键像在其他编辑器中那样工作:

  • 删除光标前的字符。
  • 删除游标前的选定内容。
  • 在所有类型的文件/模式中
  • 没有别的,没有压痕计算什么的

我正在Fedora 22上运行emacs GNU Emacs 24.5.1

我如何在emacs中实现这一点?

EN

回答 1

Stack Overflow用户

发布于 2016-06-03 18:18:42

大多数模式(主要模式或次要模式)不会重新定义<backspace>键,但它们在技术上都是免费的(参见node/elisp/Key-Binding-Conventions.html)。python-mode重新绑定<backspace> (实际上是DEL<backspace>别名,从C-h k <backspace>中可以看到)。

代码语言:javascript
复制
(with-eval-after-load "python"
  (define-key python-mode-map (kbd "DEL") nil))

对于每一种重新定义<backspace>的模式,您都需要这样做。foo-mode-mapfoo-mode的密钥映射的常规名称,但是有些模式有多个键映射和/或不同的变量名。with-eval-after-load后面的字符串是.el文件的名称;我们需要在加载它之后运行代码,因为键映射在此之前是未定义的。

若要使用巨型锤子,请参见以下答案:https://stackoverflow.com/a/34404700/245173

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37532303

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档