简体   繁体   English

在Perl模式的Emacs中关闭自动缩进

[英]Turn off auto-indent in perl-mode emacs

When I use Emacs, I turn of any auto indentation and use a custom indentation scheme (keep indentation of previous line, only using spaces). 使用Emacs时,我会关闭所有自动缩进并使用自定义缩进方案(保留前一行的缩进,仅使用空格)。

In c-mode I just used Cc Cl to turn off electric mode. 在c模式下,我只是使用Cc Cl来关闭电动模式。

But in perl-mode I'm not sure how to achieve the same. 但是在perl模式下,我不确定如何实现相同的功能。

Looking at http://mirror.fraunhofer.de/CPAN/misc/emacs/perl-mode.el . 查看http://mirror.fraunhofer.de/CPAN/misc/emacs/perl-mode.el I can see 我可以看到

(defvar perl-mode-map ()
  "Keymap used in Perl mode.")
(if perl-mode-map
    ()
  (setq perl-mode-map (make-sparse-keymap))
  (define-key perl-mode-map "{" 'electric-perl-terminator)
  (define-key perl-mode-map "}" 'electric-perl-terminator)
  (define-key perl-mode-map ";" 'electric-perl-terminator)
  ...

So I tried Mx set-variable perl-mode-map , but I only get [No match] . 所以我尝试了Mx set-variable perl-mode-map ,但是我只得到[No match]

Is this because my perl-mode.el is precompiled? 这是因为我的perl-mode.el已预编译吗? When I try to Mx find-function perl-mode it complains that it can't find it perl-mode.el . 当我尝试使用Mx find-function perl-mode它抱怨找不到perl-mode.el。 I do however have a perl-mode.elc file though. 但是,我确实有一个perl-mode.elc文件。

I am running emacs through a console on cygwin. 我正在通过cygwin上的控制台运行emacs。

Add following code your configuration file(.emacs or ~/.emacs.d/init.el) 将以下代码添加到您的配置文件(.emacs或〜/ .emacs.d / init.el)

(defun perl-mode-disable-auto-indent ()
  (local-unset-key (kbd "{"))
  (local-unset-key (kbd "}"))
  (local-unset-key (kbd ";"))
  (local-unset-key (kbd ":")))

(add-hook 'perl-mode-hook 'perl-mode-disable-auto-indent)

My bad.I didn't realise there were normal variables and user option variables in emacs. 糟糕,我没有意识到emacs中有普通变量和用户选项变量。

Running (setq perl-mode-map (make-sparse-keymap)) in the scratch buffer then reloading perl-mode disabled the electric indentation for me. 在暂存缓冲区中运行(setq perl-mode-map (make-sparse-keymap)) ,然后重新加载perl-mode会禁用我的电压痕。

Also, thanks for the answer syohex. 另外,感谢您回答syohex。

EDIT: It is important to reload perl-mode for this to work. 编辑: 重要的是要重新加载perl-mode才能起作用。

Turn off electric-indent-mode for perl-mode is how I do it. 我是如何关闭perl-mode electric-indent-mode的。 I add the following in my ~/.emacs.d/init.el 我在~/.emacs.d/init.el添加以下~/.emacs.d/init.el

(defun perl-mode-disable-auto-indent()
    (electric-indent-mode -1))
(add-hook 'perl-mode-hook 'perl-mode-disable-auto-indent)

You can find similar posts here , here , and here 您可以在此处此处此处找到类似的帖子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM