Turn off auto-indent in perl-mode emacs

1k Views Asked by At

When I use Emacs, I turn of any auto indentation and use a custom indentation scheme (keep indentation of previous line, only using spaces).

In c-mode I just used C-c C-l to turn off electric mode.

But in perl-mode I'm not sure how to achieve the same.

Looking at 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 M-x set-variable perl-mode-map, but I only get [No match].

Is this because my perl-mode.el is precompiled? When I try to M-x find-function perl-mode it complains that it can't find it perl-mode.el . I do however have a perl-mode.elc file though.

I am running emacs through a console on cygwin.

3

There are 3 best solutions below

0
rhlee On BEST ANSWER

My bad.I didn't realise there were normal variables and user option variables in emacs.

Running (setq perl-mode-map (make-sparse-keymap)) in the scratch buffer then reloading perl-mode disabled the electric indentation for me.

Also, thanks for the answer syohex.

EDIT: It is important to reload perl-mode for this to work.

0
syohex On

Add following code your configuration file(.emacs or ~/.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)
0
xxks-kkk On

Turn off electric-indent-mode for perl-mode is how I do it. I add the following in my ~/.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