在Emacs ruby模式下使用制表符而不是空格进行缩进
我一直在尝试配置Emacs,以便在缩进Ruby代码时插入一个“tab”而不是一系列“空格” 到目前为止,我已经尝试将var在Emacs ruby模式下使用制表符而不是空格进行缩进,ruby,emacs,indentation,Ruby,Emacs,Indentation,我一直在尝试配置Emacs,以便在缩进Ruby代码时插入一个“tab”而不是一系列“空格” 到目前为止,我已经尝试将varruby缩进制表符模式设置为t,这样,根据文档,它将“在ruby模式下插入制表符,如果这不是nil”。但到目前为止,还没有骰子 我还尝试通过Easy customization对其进行定制,它将以下内容插入我的init.el: (custom-set-variables ;; custom-set-variables was added by Custom. ;; If
ruby缩进制表符模式设置为t
,这样,根据文档,它将“在ruby模式下插入制表符,如果这不是nil”。但到目前为止,还没有骰子
我还尝试通过Easy customization
对其进行定制,它将以下内容插入我的init.el
:
(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.
'(ruby-indent-tabs-mode t))
(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.
)
通过C-h v检查变量后,报告变量设置为t
,但按TAB键继续插入空格
我甚至尝试为ruby模式编辑.el
文件,并重新编译它,但没有效果
我们将不胜感激
----编辑---
以下是通过C-h m报告激活的次要模式:
启用次要模式:Abbrev自动完成自动合成
自动压缩自动加密文件名阴影字体锁
全局自动完成全局字体锁定Inf Ruby行号菜单栏
显示Smartparens显示Smartparens全局Smartparens
Smartparens全局瞬态标记
init.el
文件当前具有:
(require 'cask "/Users/snowingheart/.cask/cask.el")
(cask-initialize)
(require 'pallet)
(add-to-list 'load-path "~/elisp")
(load "php-mode")
(add-to-list 'auto-mode-alist
'("\\.php[34]?\\'\\|\\.phtml\\'" . php-mode))
(global-set-key (kbd "C-x <up>") 'windmove-up)
(global-set-key (kbd "C-x <down>") 'windmove-down)
(global-set-key (kbd "C-x <right>") 'windmove-right)
(global-set-key (kbd "C-x <left>") 'windmove-left)
(require 'package)
(add-to-list 'package-archives
'("marmalade" .
"http://marmalade-repo.org/packages/"))
(package-initialize)
(global-set-key (kbd "C-x >") 'mc/mark-next-like-this)
(global-set-key (kbd "C-x <") 'mc/mark-previous-like-this)
(global-set-key (kbd "C-c C-<") 'mc/mark-all-like-this)
(global-set-key (kbd "C-S-c C-S-c") 'mc/edit-lines)
(require 'smartparens-config)
(require 'smartparens-ruby)
(require 'smartparens-erb)
(smartparens-global-mode)
(show-smartparens-global-mode t)
(sp-with-modes '(rhtml-mode)
(sp-local-pair "<%=" "%>")
(sp-local-pair "<%-" "%>"))
(require 'auto-complete-config)
(add-to-list 'ac-dictionary-directories
"~/.emacs.d/.cask/24.3.50.1/elpa/auto-complete-20130724.1750/dict")
(ac-config-default)
(setq ac-ignore-case nil)
(add-to-list 'ac-modes 'enh-ruby-mode)
(add-to-list 'ac-modes 'web-mode)
(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.
'(indent-tabs-mode t)
'(ruby-indent-tabs-mode t))
(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.
)
(setq-default indent-tabs-mode t)
(setq enh-ruby-indent-tabs-mode t)
(smart-tabs-insinuate 'ruby)
(smart-tabs-advice ruby-indent-line ruby-indent-level)
(setq ruby-indent-tabs-mode t)
(需要“cask”/Users/snowingheart/.cask/cask.el)
(容器初始化)
(需要“托盘”)
(添加到列表“加载路径”~/elisp”)
(加载“php模式”)
(添加到“自动模式”列表中)
“(“\\.php[34]?\\'\\\\\\\.phtml\\'”.php模式))
(全局设置键(kbd“C-x”)‘windmove up)
(全局设置键(kbd“C-x”)“windmove down”
(全局设置键(kbd“C-x”)‘windmove right)
(全局设置键(kbd“C-x”)‘windmove left)
(需要“包”)
(添加到“文件包档案”列表中
(“果酱”。
"http://marmalade-repo.org/packages/"))
(包初始化)
(全局设置键(kbd“C-x>”)mc/下一步按此标记)
(全局设置键(kbd“C-x尝试将以下内容添加到您的init.el
(在您已有的自定义项下面):
从缩进选项卡模式的文档中
:
如果缩进为非零,则缩进可以插入制表符
我不使用ruby模式
,因此我不知道indent tabs模式
和ruby indent tabs模式
之间可能存在的交互。只需将indent tabs模式
设置为t
(并删除您对ruby indent tabs模式
所做的自定义设置即可)。但是,当您将上面的代码段添加到配置中时,Emacs的默认行为将是插入缩进选项卡
编辑
可以看出,定义了一个名为enh ruby indent tabs mode
的自定义变量,默认值为nil
。该变量的值用于覆盖indent tabs mode
的值,这就是为什么将indent tabs mode
设置为t
对具有enh ruby mo>的缓冲区没有影响de
已启用
因此,除非启用除ruby模式
和enh ruby模式
之外的任何其他模式,否则可能会修改indent tabs模式
变量,添加
(setq enh-ruby-indent-tabs-mode t)
到您的init.el
应该可以解决您的问题
另一个编辑(工作解决方案)
(学分:让我走上正确的轨道。)
使用
- Emacs24.3.1
ruby模式
版本1.2(内置)
enh-ruby模式
version20140406.252(通过M-x软件包安装安装
…)
我可以通过将以下内容添加到一个完全为空的init.el
文件中来实现:
(package-initialize)
(setq-default tab-width 2)
(setq enh-ruby-indent-tabs-mode t)
(defvaralias 'enh-ruby-indent-level 'tab-width)
(defvaralias 'enh-ruby-hanging-indent-level 'tab-width)
此解决方案适用于GUI和Emacs的控制台版本。它可能会与其他定制很好地集成,但您需要从上面发布的init.el
版本中删除custom set variables
部分及其下的所有内容
另外请注意,如果遇到Emacs插入空格而不是选项卡的情况,您可以随时删除它,并通过C-q选项卡强制插入选项卡
收尾
当enh-ruby-indent-tabs-mode
设置为t
时,enh-ruby-mode
中存在一个导致从第二级开始的块缩进失败的缩进模式。enh-ruby-mode
的作者/维护者没有修复该模式的计划,但bug报告中包含了一个据说可以修复该问题的补丁 请重新考虑使用制表符和空格。制表符在不同的编辑器中显示不同,特别是当其他人配置它们时,可能会使代码对齐严重中断。有些人希望制表符显示为两个空格,另一些人希望显示为四个空格,还有一些人希望显示为八个空格。因此,在Ruby中,我们使用两个空格作为in缩进,而不是制表符,以保持代码编写的一致性。缩进不仅仅是为了您的舒适,也是为了那些维护或继承您的代码的人。我非常同意您的看法。问题是,这对我的同事和我的同事都没有好处。他的编辑(sublime)显示用制表符缩进的代码,在处理相同的文件时,当我交出两行间距的文件时,事情往往会中断。类似这样的情况如何,但改为Ruby模式?:我不确定在Ruby模式下,我的链接中的代码可能还需要更改哪些内容才能正常工作。我将该代码与文本模式挂钩一起使用,并且它会在被我通常使用的其他主要模式所忽略。你的意思是将org mode hook
更改为ruby mode hook
,对吗?它确实改变了TAB键的行为,但不再缩进(就像在TAB之后插入TAB…)@snowingheart:Sublime文本在这方面是完全可配置的。它甚至会检查文件,试图猜测缩进间隔是什么。我不明白为什么这是你的问题,而不是你的问题
(package-initialize)
(setq-default tab-width 2)
(setq enh-ruby-indent-tabs-mode t)
(defvaralias 'enh-ruby-indent-level 'tab-width)
(defvaralias 'enh-ruby-hanging-indent-level 'tab-width)