简体   繁体   English

如何在php / html文件打开时使emacs加载nXhtml并阻止它在启动时加载

[英]How can I make emacs load nXhtml only when php/html files are open and prevent it from loading at startup

So in order to optimize emacs startup time I prefer to encapsualte all mods within a hook or an eval-after-load. 因此,为了优化emacs启动时间,我更喜欢在钩子或eval-after-load中封装所有mod。 So I figured out python, cpp and latex but am stuck with nXhtml. 所以我想出了python,cpp和latex,但我坚持使用nXhtml。 I tried the following: 我尝试了以下方法:

(eval-after-load "HTML-mode"
'(progn
(load-file "~/.emacs.d/plugins/nxhtml/autostart.el")
))

Which doesn't work at all. 这根本不起作用。

The code : 编码 :

(add-hook 'html-mode-hook (lambda()
(progn
  (load-file "~/.emacs.d/plugins/nxhtml/autostart.el")
)))

loads some parts of nXhtml but the nXhtml mode is not on (only SGML and AC) so scopes aren't colored differently in my php sources or autocomplete/ bracket completion doesn't work. 加载nXhtml的某些部分,但是nXhtml模式没有打开(只有SGML和AC),因此我的php源中的范围没有不同的颜色,或者自动完成/括号完成不起作用。

The only way it works properly is if I let it load on startup. 它正常工作的唯一方法是我在启动时加载它。

Looking at the trace , when nxhtml is loaded during startup it says : 查看跟踪,当在启动期间加载nxhtml时,它说:

"majmodpri-apply-priorities running ... (done)" “majmodpri-apply-priorities running ...(已完成)”

However when the load is encapsulated by an html-mode-hook or the eval-after-load the trace says: 但是当负载由html-mode-hook或eval-after-load封装时,跟踪显示:

"majmodpri-apply-priorities running ... MU:majmodpri-check changing majmodpri-apply-priorities: buffer=index.php, html-mode,nil => sgml-mode,nil majmodpri-apply-priorities running ... (done)" “运行majmodpri-apply-priorities ... MU:majmodpri-check更改majmodpri-apply-priorities:buffer = index.php,html-mode,nil => sgml-mode,nil majmodpri-apply-priorities running ...(完成)”

Any ideas? 有任何想法吗?

I think nXhtml's autostart file (which is all that you would be loading) is designed to be fairly minimal, so it might be the case that you can't reduce it too much more without constraining some of its abilities? 我认为nXhtml的自动启动文件(这就是你要加载的所有文件)被设计得相当小,所以可能是你不能在不限制它的某些能力的情况下减少它太多的情况?

How long is it actually taking? 它实际需要多长时间? It looks like there should be a "Nxml/Nxhtml Autostart.el loaded in %.1f seconds" message logged. 看起来应该记录“在%.1f秒内加载Nxml / Nxhtml Autostart.el”消息。

Infact html-mode is defined in sgml-mode.el file. 事实上html-mode在sgml-mode.el文件中定义。

So you eval-after-load should be as follows 因此, eval-after-load应如下所示

(eval-after-load "sgml-mode" (lambda ()
;;;  code to load your nxhtml
                               ))

I also use nxhtml-mode to edit the erb documents when I programming ROR app. 我在编写ROR应用程序时也使用nxhtml-mode来编辑erb文档。 Take a look at my configuration, this may help you. 看看我的配置,这可能会对你有所帮助。

(autoload 'eruby-nxhtml-mumamo-mode "autostart.el" "Edit erb document." t)
(add-to-list 'auto-mode-alist '("\\.erb" . eruby-nxhtml-mumamo-mode))

I just combined the OP code and it works for me: 我只是结合了OP代码,它对我有用:

(add-hook 'html-mode-hook (lambda()
(progn
  (load-file "~/.emacs.d/vendor/~nxhtml/nxhtml/main/autostart.el")
))) 

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

相关问题 如何获得emacs来区别编写PHP,HTML和JavaScript时的区别? - How can I get emacs to tell the difference from when I am writing PHP, HTML, and JavaScript? 将PHP文件导入HTML文档时,如何防止Meta和Title标签注入? - When importing PHP files into an HTML document, how do I prevent the Meta and Title tags from injecting? 如何防止 PHP HTML type=“hidden” 损坏? - How can I prevent PHP HTML type=“hidden” from breaking? 如何将文件夹中的多个html文件加载到div中 - How can I load multiple html files from a folder into a div 如何在用户登录时仅加载一次requireJs文件,并防止在每次重新加载页面时加载它 - How to load requireJs file only once when a user login and prevent it from loading every time page re-loads 如何加载外部html文件? - How can I load external html files? 如何使html打开lua文件或打开exe? - How can I make html open a lua file or open a exe? 如何防止 Chrome 在离线时加载缓存的网页? - How can I prevent Chrome from loading a cached webpage when offline? 如何在页面加载时打开此模式对话框? - How can I make this modal dialog open on page load? 如何防止 Bootstrap 轮播图像堆叠? HTML/CSS(使用 PHP 显示图像) - How can I prevent Bootstrap carousel images from stacking? HTML/CSS (using PHP to display images)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM