简体   繁体   English

如何为Clojure,邪恶,提示,括号突出显示设置emacs?

[英]How to set up emacs for clojure, evil, hinting, paren highlighting?

I'm brand-new to both Emacs and Clojure and would like to set up hinting and syntax highlighting somehow similar to the video here . 我对Emacs和Clojure都是陌生的,并希望设置提示和语法突出显示方式,类似于此处的视频。 I have installed: 我已经安装了:

  • Emacs 24.x Emacs 24.x
  • Leiningen 2.x 莱宁根2.x
  • Marmalade 果酱

...Then within Emacs and via Marmalade, installed the following packages: ...然后在Emacs中和通过Marmalade安装了以下软件包:

  • Evil 邪恶
  • clojure-mode Clojure的模式
  • nrepl nrepl

My big-idea question is how do these major/minor modes interact and is there a "right" way to set these things up? 我的主要思想是这些主要/次要模式如何相互作用,是否有“正确”的方式来设置这些内容?
My smaller-idea question is how do I get the pretty syntax highlighting and code-hinting? 我的小想法问题是如何获得漂亮的语法突出显示和代码提示? Thanks! 谢谢!

Check out Emacs Live, its a full emacs configuration created by Sam Aaron. 查看Emacs Live,它是由Sam Aaron创建的完整emacs配置。 He codes allot of Clojure so this "battery included" setup works great for Clojure coding. 他对Clojure的分配进行编码,因此此“包括电池”设置非常适合Clojure编码。

https://github.com/overtone/emacs-live https://github.com/overtone/emacs-live

Once you have cloned this and follow the instructions you are up and running with Clojure, nrepl, git and much more. 克隆此文件并按照说明进行操作后,即可使用Clojure,nrepl,git等启动并运行。

I list my setup. 我列出了我的设置。 Some of the stuff is redundant, since I haven't written in Clojure for a while, but I checked and it still works. 有些东西是多余的,因为我已经有一段时间没有用Clojure编写了,但是我检查了一下,它仍然有效。

  1. Use clojure to start nrepl. 使用clojure启动nrepl。 You might have some issue with project.clj being in the appropriate directory, but you should figure this out. 您可能在适当的目录中找到了project.clj问题,但是您应该弄清楚这一点。
  2. Open a source file eg foo.clj . 打开一个源文件,例如foo.clj
  3. Use Cc Cl to call nrepl-load-file By the way, it's the canonical shortcut to load the file into inferior process. 使用Cc Cl调用nrepl-load-file顺便说一句,将文件加载到劣等进程是规范的快捷方式。 It will work for Common Lisp, Python etc. 它将适用于Common Lisp,Python等。
  4. Use Cc Cz to switch to repl. 使用Cc Cz切换到repl。 This again is the canonical shortcut that works for many languages. 这再次是适用于多种语言的规范快捷方式。

Here's the setup code: 这是设置代码:

(require 'clojure-mode)
(defun set-syntax-parens ()
  "highlight []{} etc."
  (interactive)
  (modify-syntax-entry ?[ "(]")
  (modify-syntax-entry ?] ")[")
  (modify-syntax-entry ?{ "(}")
  (modify-syntax-entry ?} "){"))
(defvar clojure.jars '("clojure-1.3.0.jar" 
                       "swank-clojure-1.4.2.jar" 
                       "clojure-contrib-1.2.0.jar"))
(defvar clojure.jars.d (concat dropbox.d "source/clojure/lib/"))
(defvar clojure.classpath 
  (apply #'concat 
         (mapcar (lambda (jar) (concat clojure.jars.d jar path-separator)) 
                 clojure.jars)))
(setq clojure.classpath 
      (concat clojure.classpath 
              dropbox.d "source/clojure/include/" 
              path-separator))
;;;###autoload
(defun clojure ()
  (interactive)
  (nrepl-jack-in))
(defvar clojure-server-cmd 
  (concat "java -Xss4096k -cp " clojure.classpath " clojure.main &"))
(add-hook 'clojure-mode-hook
      (lambda()
        (set-syntax-parens)))
(require 'nrepl)
(add-hook 'nrepl-mode-hook
      (lambda()
        (define-key nrepl-mode-map (kbd "C-l") 'nrepl-clear-buffer)))

here is the operative section from my favorite emacs config : 这是我最喜欢的emacs配置的执行部分:

(when (not package-archive-contents)                                                                                                                                      
  (package-refresh-contents))                                                                                                                                             

;; Add in your own as you wish:                                                                                                                                           
(defvar my-packages '(starter-kit starter-kit-lisp starter-kit-bindings clojure-mode                                                                                      
                       nrepl auto-complete ac-nrepl org rainbow-delimiters)                                                                                                
  "A list of packages to ensure are installed at launch.")                                                                                                                

(dolist (p my-packages)                                                                                                                                                   
  (when (not (package-installed-p p))                                                                                                                                     
    (package-install p)))                                                                                                                                                 

(require 'ac-nrepl)                                                                                                                                                       
(add-hook 'nrepl-mode-hook 'ac-nrepl-setup)                                                                                                                               
(add-hook 'nrepl-interaction-mode-hook 'ac-nrepl-setup)                                                                                                                   
(eval-after-load "auto-complete"                                                                                                                                          
     '(add-to-list 'ac-modes 'nrepl-mode))                                                                                                                                
(defun set-auto-complete-as-completion-at-point-function ()                                                                                                               
  (setq completion-at-point-functions '(auto-complete)))                                                                                                                  

(add-hook 'auto-complete-mode-hook 'set-auto-complete-as-completion-at-point-function)                                                                                    

(add-hook 'nrepl-mode-hook 'set-auto-complete-as-completion-at-point-function)                                                                                            
(add-hook 'nrepl-interaction-mode-hook 'set-auto-complete-as-completion-at-point-function)                                                                                
(define-key nrepl-interaction-mode-map (kbd "C-c C-d") 'ac-nrepl-popup-doc)                                                                                               
(add-hook 'prog-mode-hook 'auto-complete-mode)                                                                                                                            

(add-hook 'nrepl-interaction-mode-hook                                                                                                                                    
          'nrepl-turn-on-eldoc-mode)                                                                                                                                    

(add-hook 'nrepl-mode-hook 'paredit-mode) 

This turns on paredit-mode everywhere, which takes a bit of getting used to though it's entirely worth it because paredit and makes using Clojure much more fun . 这将在任何地方都启用paredit模式 ,尽管这完全值得,但要花一点时间来习惯一下,因为paredit使得使用Clojure更加有趣 At least once you get a handle on slurping and barfing 至少一旦您掌握了lur食和推倒的能力

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM