[英]How can I configure so that I can define multiple actions in cperl-mode-hook in .emacs?
Here is an excerpt of my .emacs 这是我的.emacs的摘录
CASE 1: With the config below, perl-completion mode works perfectly. 情况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)
CASE 2: With the config below, Cc Cc in cperl-mode will successfully launch perl compilation. 情况2:使用以下配置,处于cperl模式的Cc Cc将成功启动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)
CASE 3: However, with the code below to have both of perl-completion and Cc Cc to launch perl compilattion enabled by uncommenting all of lines in hook function (my-cperl-hook-func), it just ends up with that perl-completion would work fine while Cc Cc won't work at all (emacs says Cc Cc is undefined.) 情况3:但是,下面的代码通过取消对钩子函数(my-cperl-hook-func)中的所有行进行注释,使perl-completion和Cc Cc能够启动perl编译,它最终以perl-完成操作会很好,而Cc Cc则根本无法工作(emacs说Cc Cc是未定义的。)
How can I make both of actions valid in cperl-mode-hook? 如何在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)
First off, if you are using elpa and the package system to install perl-completion
, it will automatically add it to the load path, so the add-to-list load-path
is unnecessary. 首先,如果您使用elpa和软件包系统来安装
perl-completion
,它将自动将其添加到加载路径,因此不需要add-to-list load-path
。 Unfortunately the package does not include an autoload for perl-completion-mode
, so the (require 'perl-completion)
is necessary. 不幸的是,该软件包不包括
perl-completion-mode
的自动加载,因此(require 'perl-completion)
是必需的。
After examining the perl-completion
library at http://www.emacswiki.org/emacs/perl-completion.el , it appears it uses Cc Cc
as a prefix. 在检查了http://www.emacswiki.org/emacs/perl-completion.el上的
perl-completion
库之后,似乎它使用Cc Cc
作为前缀。 Unfortunately, by using it as a prefix, it is clobbering the ability to bind Cc Cc
for compile
in perl-mode
. 不幸的是,通过使用它作为前缀,它破坏了绑定
Cc Cc
以便在perl-mode
进行compile
的能力。
I used the following to test this, and to bind compile to Cc Cc c
. 我使用以下代码对此进行了测试,并将其绑定到
Cc Cc 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)
Saved as cperl-init.el
, and run with no other packages using emacs -q -l cperl-init.el
. 保存为
cperl-init.el
,并且不使用emacs -q -l cperl-init.el
与其他软件包一起运行。
If you want to use Cc Cc
for compile I think you have to unbind it's use in perl-completion. 如果要使用
Cc Cc
进行编译,我认为您必须取消绑定它在perl-completion中的使用。 It looks like cperl itself has some compatibility with mode-compile, but not sure if it adds any bindings. 看起来cperl本身与mode-compile有一些兼容性,但是不确定是否添加任何绑定。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.