码迷,mamicode.com
首页 > Web开发 > 详细

emacs搭建web开发环境

时间:2015-02-24 21:04:08      阅读:464      评论:0      收藏:0      [点我收藏+]

标签:emacs   hook   web开发   浏览器   html   

web-mode

About

web-mode.el is an autonomous emacs major-mode for editing web templates.
HTML documents can embed parts (CSS / JavaScript) and blocks (client / server side).

Download

Install

(require 'web-mode)

(add-to-list 'auto-mode-alist '("\\.html?\\'" . web-mode))

;; indent setting
(defun my-web-mode-hook ()
  "Hooks for Web mode."
  (setq web-mode-markup-indent-offset 2)
)
(add-hook 'web-mode-hook  'my-web-mode-hook)


;; comment style setting
(setq web-mode-comment-style 2)


emacs中调用外部浏览器打开html文档

emacs默认的html-mode

emacs打开html文档时默认会调用html-mode,html-mode中有一个默认的键绑定 C-c C-v,view buffer contents ,可以实现调用外部浏览器打开html文档

browse-url-of-buffer

我们可以使用C-h k , 输入C-c C-v ,来查看这个键绑定的内容

C-c C-v runs the command browse-url-of-buffer, which is an interactive
compiled Lisp function.

It is bound to C-c C-v, <menu-bar> <html> <browse-url-of-buffer>.

(browse-url-of-buffer &optional BUFFER)

Ask a WWW browser to display BUFFER.
Display the current buffer if BUFFER is nil.  Display only the
currently visible part of BUFFER (from a temporary file) if buffer is
narrowed.

从上面的内容可以看出这个键绑定是调用 browse-url-of-buffer函数来实现这个功能

在web-mode中绑定按键来调用上述函数

(defun web-mode-keybinding-settings ()
  "Settings for keybinding."
  (eal-define-keys
   '(web-mode-map)
   '(("C-c C-v" browse-url-of-file))))

(eval-after-load "web-mode-keybinding-settings"
  '(web-mode-keybinding-settings))

定义web-mode中的键绑定C-c C-v 调用上述函数,在其他mode中这个快捷键不起作用

web-settings.el

(require 'web-mode)

(add-to-list 'auto-mode-alist '("\\.html?\\'" . web-mode))

;; indent setting
(defun my-web-mode-hook ()
  "Hooks for Web mode."
  (setq web-mode-markup-indent-offset 2)
)
(add-hook 'web-mode-hook  'my-web-mode-hook)


;; comment style setting
(setq web-mode-comment-style 2)

;; keybinding
(defun web-mode-keybinding-settings ()
  "Settings for keybinding."
  (eal-define-keys
   '(web-mode-map)
   '(("C-c C-v" browse-url-of-file))))

(eval-after-load "web-mode-keybinding-settings"
  '(web-mode-keybinding-settings))
   
(provide 'web-settings)




emacs搭建web开发环境

标签:emacs   hook   web开发   浏览器   html   

原文地址:http://blog.csdn.net/one___thousand/article/details/43926697

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!