.emacs的helloworld

本文介绍了Emacs的个性化配置方法,包括基本设置、自动提示、代码补全等功能的实现,并提供了具体的配置代码示例。
webrtc :http://www.lookybang.cc/forum.php?mod=viewthread&tid=409&extra=page%3D1

emacs
[color=red]F10是菜单[/color]
编译el
emacs --batch -f batch-byte-compile haoning.el

查看变量定义
[color=red]c-h v[/color]

[b]etags使用[/b]

find -name "*.[chCH]" -exec etags -a {} ;
  或
find . -name "*.[chCH]" -print | etags -
创建好tag表后,告知emacs。
  M-x visit-tags-table
在.emacs中加入这样的语句:
  (setq tags-file-name "~/sim973/src/TAGS")
M-. 查找一个tag,比如函数定义类型定义等。
  C-u M-. 查找下一个tag的位置
  M-* 回到上一次运行M-.前的光标位置。
  M-TAB 自动补齐函数名。


[color=darkred]安装auto-complete后,只要emacs打开的文件都可以自动补全,
比如看的是c的代码,
我们可以把TAGS复制成TAGS.c然后,c-x c-f 打开TAGS.c
这样就可以即使用etags又使用自动补全了[/color]


.emacs

(require 'package)
(dolist (source '(("elpa" . "http://tromey.com/elpa/")
("melpa" . "http://melpa.milkbox.net/packages/")
))
(add-to-list 'package-archives source t))
(package-initialize)

(load-file "~/.emacs.d/hao-base.el")
(load-file "~/.emacs.d/hao-complete.el")
(load-file "~/.emacs.d/hao-study.el")
;(load-file "~/.emacs.d/hao-js.el")
(setq tags-file-name "/root/haoning/nginx-1.9.4/TAGS")


基本设置
hao-base.el

(setq indent-tabs-mode nil)
(setq default-tab-width 4)
(setq tab-width 4)
(show-paren-mode t)
(setq frame-title-format "haoning@%b")


自动提示,需要list-packages安装auto-complete,
auto-yasnippets
hao-complete.el

;;m-x list-packages; c-s auto-complete
(require 'auto-complete)
(require 'auto-complete-config)
(global-auto-complete-mode t)
(autoload 'auto-complete-mode "auto-complete-mode" nil t)
;(add-to-list 'ac-dictionary-directories "~/.emacs.d/elpa/auto-complete-20150618.1949/dict")
(ac-config-default)
(setq ac-use-quick-help nil)
(setq ac-auto-start 4) ;; 输入4个字符才开始补全
(global-set-key "\M-/" 'auto-complete) ;; 补全的快捷键,用于需要提前补全
(setq ac-auto-show-menu 0.8);; Show menu 0.8 second later
;; 选择菜单项的快捷键
(setq ac-use-menu-map t)
(define-key ac-menu-map "\C-n" 'ac-next)
(define-key ac-menu-map "\C-p" 'ac-previous)
(setq ac-menu-height 15);; menu设置为15 lines

;;;;;yasnippets
(defun dot-emacs (relative-path)
"Return the full path of a file in the user's emacs directory."
(expand-file-name (concat user-emacs-directory relative-path)))
(require 'yasnippet)
(yas/initialize)
(yas/load-directory (dot-emacs "elpa/yasnippet-20151108.1505/snippets"))


学习lisp的helloworld的
<<Emacs Lisp 15 分钟入门>>
参考[url]http://blog.jobbole.com/44932/[/url]
hao-study.el

(setq inhibit-startup-message t)
(setq gnus-inhibit-startup-message t)

;(switch-to-buffer-other-window "*haoning*")
(switch-to-buffer "*haoning*")
(setq my-name "haoning")
(insert "hello\n")
(insert my-name "\n")
;c-h v my-name
;c-x c-b scratch scratch

(defun hello () (insert "Hello, I am " my-name "\n"))
(hello)

(defun helloworld (name) (insert (format "hello, %s \n" name)))
(helloworld "you")

;(other-window 0)
(progn
;(switch-to-buffer-other-window "*test*")
;(erase-buffer)
(helloworld "your brothor")
;(other-window 1)
)

(let ((local-name "your sister"))
;(switch-to-buffer-other-window "*test*")
;(erase-buffer)
(helloworld local-name)
;(other-window 1)
)

;(defun greeting (from-name)
; (let ((your-name (read-from-minibuffer "hi haoning Enter your like : ")))
; (switch-to-buffer-other-window "*test*")
;; (erase-buffer)
; (insert (format "greeting(): hello %s!\n\nI am %s." your-name from-name))
; (other-window 1))
;)
;(greeting "zhy")


(setq list-of-names '("haohao" "ningning" "zhy"))
(car list-of-names)
(cdr list-of-names)
(push "mylove" list-of-names)

(mapcar 'helloworld list-of-names)

(defun mygreeting ()
;(switch-to-buffer-other-window "*test*")
; (erase-buffer)
(mapcar 'helloworld list-of-names)
;(other-window 1)
)
(mygreeting)


;(defun replace-hello-by-nihao ()
; ;(switch-to-buffer-other-window "*test*")
; (goto-char (point-min))
; (while (search-forward "hello" nil t)
; (replace-match "nihao")
; )
; ;(other-window 1)
;)
;(replace-hello-by-nihao)
;
;; 其中 nil参数表示 搜索的区域不加限制,直到buffer结束
;; 其中t参数指示search-foward函数 跳过错误信息 直接退出

;(list 'face 'bold)
;(defun boldify-names ()
; ;(switch-to-buffer-other-window "*test*")
; (goto-char (point-min))
; (insert "this is beginning -----\n")
; ;(while (re-search-forward "hao\\(.+\\).+!" nil t)
; (while (re-search-forward "hao" nil t)
; ;(insert "\n ---hahahah---\n")
; (add-text-properties (match-beginning 1) ;返回匹配模式中,最先匹配的位置
; (match-end 1) ;返回最后匹配的位置
; (list 'face 'bold)
; )
; )
; (insert "\nthis is ending ------")
; ;(other-window 1)
;)
;
;(boldify-names)


js2-mode
参考<<用emacs打造node.js开发环境>>
[url]http://www.open-open.com/lib/view/open1391687309114.html[/url]
有些似乎不好使
hao-js.el

(add-to-list 'load-path "~/.emacs.d/elpa/js2-mode-20151107.950")
(autoload 'js2-mode "js2-mode" nil t)
(add-to-list 'auto-mode-alist '("\\.js$" . js2-mode))


(load-file "~/.emacs.d/espresso.el")
(load-file "~/.emacs.d/nodejs.el")
(require 'nodejs)

;(load-file "~/.emacs.d/js2-highlight-vars.el")
;(require 'js2-highlight-vars)
;(if (featurep 'js2-highlight-vars)
; (js2-highlight-vars-mode)
;)
<think>根据用户的历史对话和当前问题,用户之前要求用Malbogle写HelloWorld程序,由于Malbogle是虚构语言,我推测了两种实现方案。现在用户明确提到想用Lisp写HelloWorld,并在引用中给出了EmacsLisp的示例。用户当前问题是:“我想使用Lisp编写一个Helloworld程序请问如何用Lisp编写Helloworld程序”从引用内容看:-引用[1]给出了EmacsLisp的HelloWorld示例:(defunhello-world()(interactive)(message"Hello,World!"))(hello-world)-引用[2][3][4]提到不同编程语言的HelloWorld程序所以这次要针对真正的Lisp语言回答,需区分Lisp方言:1.通用Lisp(CommonLisp)2.Scheme3.EmacsLisp(已在引用[1]中给出)4.Clojure考虑设计分步骤回答:-第一步:介绍Lisp编写HelloWorld的核心方法(不同方言)-第二步:给每个主要方言提供代码示例-第三步:执行方式说明-第四步:相关问题需注意用户引用中强调的格式要求:-中文回答-LaTeX数学公式用$...$或$$...$$-代码块单独标记-相关问题列表虽然HelloWorld不涉及数学公式,但考虑在解释原理时使用Lisp表达式结构说明,如用行内公式:$(\mathrm{print}\"\text{HelloWorld}")$最终回答结构:1.开头解释Lisp的HelloWorld原理2.分方言展示代码(CommonLisp/Scheme/EmacsLisp/Clojure)3.执行步骤说明4.相关问题生成</think> ### 如何用 Lisp 编写 Hello World 程序 Lisp(LISt Processor)是一种函数式编程语言家族,其核心语法基于 **S-表达式**(Symbolic Expression)。下面是不同 Lisp 方言的 Hello World 实现: #### 1. **Common Lisp** (主流标准方言) ```lisp (defun main () (format t "Hello, World!~%")) ; ~% 表示换行 (main) ; 调用函数 ``` - **说明**: `format` 是格式化输出函数,`t` 指定输出到标准流,`"~%"` 相当于换行符 `\n`[^1]。 --- #### 2. **Scheme** (简洁的 Lisp 方言) ```scheme (display "Hello, World!") (newline) ; 显式换行 ``` - **说明**: `display` 直接输出字符串,`newline` 是换行函数(非必需但推荐)[^2]。 --- #### 3. **Emacs Lisp** (用于 Emacs 编辑器) ```elisp (defun hello-world () (interactive) ; 允许通过 M-x 调用 (message "Hello, World!")) ; 在 minibuffer 显示 (hello-world) ; 直接执行 ``` - **说明**: `(interactive)` 声明可交互命令,`message` 是 Emacs 专用输出函数[^1]。 --- #### 4. **Clojure** (运行在 JVM 上的现代 Lisp) ```clojure (println "Hello, World!") ; 直接输出并换行 ``` - **说明**: `println` 是自动换行的输出宏(Macro),无需显式换行操作[^3]。 --- ### 执行步骤 1. **安装环境**(以 Common Lisp 为例): ```bash # 安装 SBCL(Steel Bank Common Lisp) sudo apt-get install sbcl # Ubuntu brew install sbcl # macOS ``` 2. **运行程序**: ```bash sbcl --script hello.lisp # 直接执行文件 ``` **输出**: ``` Hello, World! ``` --- ### 原理说明 Lisp 的 Hello World 程序依赖其核心特性: - **S-表达式**:`(函数名 参数1 参数2 ...)` 例如:$( \mathtt{(format\ t\ "Hello")} )$ - **函数式求值**:每个表达式返回计算结果 - **最小语法**:括号嵌套表示执行顺序 ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值