如何配置以便我可以在.emacs中的cperl-mode-hook中定义多个操作?

时间:2014-07-26 14:10:38

标签: emacs cperl-mode

以下是我的.emacs

的摘录

案例1:使用下面的配置,perl-completion模式可以正常工作。

;;-------------------------------------------------------
;; -*-- CPerl mode
;;-------------------------------------------------------

(defalias 'perl-mode 'cperl-mode)
(add-to-list 'auto-mode-alist '("\\.[apP][Llm]$" . cperl-mode))
(add-to-list 'auto-mode-alist '("\\.al$" . cperl-mode))
(add-to-list 'auto-mode-alist '("\\.t$" . cperl-mode))
(add-to-list 'interpreter-mode-alist '("perl" . cperl-mode))

(defun my-cperl-hook-func()
  (add-to-list 'load-path "~/.emacs.d/elpa/perl-completion-20090527.2336")
  (require 'perl-completion)
  (perl-completion-mode t)
  ;; (make-local-variable 'compile-command)
  ;;  (setq compile-command
  ;;        (concat "perl " (buffer-file-name)))
  ;;  (cperl-define-key "\C-c\C-c" 'compile)
  )

(add-hook 'cperl-mode-hook 'my-cperl-hook-func)

案例2:使用下面的配置,cperl-mode中的C-c C-c将成功启动perl编译。

;;-------------------------------------------------------
;; -*-- CPerl mode
;;-------------------------------------------------------
(defalias 'perl-mode 'cperl-mode)

(add-to-list 'auto-mode-alist '("\\.[apP][Llm]$" . cperl-mode))
(add-to-list 'auto-mode-alist '("\\.al$" . cperl-mode))
(add-to-list 'auto-mode-alist '("\\.t$" . cperl-mode))
(add-to-list 'interpreter-mode-alist '("perl" . cperl-mode))

(defun my-cperl-hook-func()
  ;; (add-to-list 'load-path "~/.emacs.d/elpa/perl-completion-20090527.2336")
  ;; (require 'perl-completion)
  ;; (perl-completion-mode t)
  (make-local-variable 'compile-command)
  (setq compile-command
        (concat "perl " (buffer-file-name)))
  (cperl-define-key "\C-c\C-c" 'compile)
  )

(add-hook 'cperl-mode-hook 'my-cperl-hook-func)

案例3:但是,使用以下代码同时通过取消注释钩子函数(my-cperl-hook-func)中的所有行来启用perl-completion和Cc Cc来启动perl compilattion,它最终会以perc-completion工作正常,而Cc Cc根本不起作用(emacs说Cc Cc未定义。)

如何在cperl-mode-hook中使这两个动作都有效?

;;-------------------------------------------------------
;; -*-- CPerl mode
;;-------------------------------------------------------
(defalias 'perl-mode 'cperl-mode)

(add-to-list 'auto-mode-alist '("\\.[apP][Llm]$" . cperl-mode))
(add-to-list 'auto-mode-alist '("\\.al$" . cperl-mode))
(add-to-list 'auto-mode-alist '("\\.t$" . cperl-mode))
(add-to-list 'interpreter-mode-alist '("perl" . cperl-mode))

(defun my-cperl-hook-func()
  (add-to-list 'load-path "~/.emacs.d/elpa/perl-completion-20090527.2336")
  (require 'perl-completion)
  (perl-completion-mode t)    
  (make-local-variable 'compile-command)
   (setq compile-command
         (concat "perl " (buffer-file-name)))
   (cperl-define-key "\C-c\C-c" 'compile)
  )

(add-hook 'cperl-mode-hook 'my-cperl-hook-func)

1 个答案:

答案 0 :(得分:1)

首先,如果您使用elpa和软件包系统来安装perl-completion,它会自动将其添加到加载路径,因此add-to-list load-path是不必要的。很遗憾,该软件包不包含perl-completion-mode的自动加载,因此(require 'perl-completion)是必需的。

http://www.emacswiki.org/emacs/perl-completion.el检查perl-completion库后,它似乎使用C-c C-c作为前缀。不幸的是,通过使用它作为前缀,它破坏了C-c C-ccompile的{​​{1}}绑定的能力。

我使用以下内容对此进行测试,并将编译绑定到perl-mode

C-c C-c c

保存为(require 'package) (add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/") t) (package-initialize) (package-refresh-contents) (package-install 'anything) (package-install 'perl-completion) ;;------------------------------------------------------- ;; -*-- CPerl mode ;;------------------------------------------------------- (defalias 'perl-mode 'cperl-mode) (add-to-list 'auto-mode-alist '("\\.[apP][Llm]$" . cperl-mode)) (add-to-list 'auto-mode-alist '("\\.al$" . cperl-mode)) (add-to-list 'auto-mode-alist '("\\.t$" . cperl-mode)) (add-to-list 'interpreter-mode-alist '("perl" . cperl-mode)) (defun my-cperl-hook-func() (require 'perl-completion) (perl-completion-mode t) (make-local-variable 'compile-command) (setq compile-command (concat "perl " (buffer-file-name))) (cperl-define-key "\C-c\C-cc" 'compile) ) (add-hook 'cperl-mode-hook 'my-cperl-hook-func) ,并使用cperl-init.el运行其他任何软件包。

如果你想使用emacs -q -l cperl-init.el进行编译,我认为你必须解除它在perl-completion中的使用。看起来cperl本身与模式编译有一些兼容性,但不确定它是否添加了任何绑定。