Skip to content

Latest commit

 

History

History
executable file
·
863 lines (663 loc) · 31.4 KB

emacs-beginners.org

File metadata and controls

executable file
·
863 lines (663 loc) · 31.4 KB

emacs projects -*- mode: org; -*- emacs for beginners http://home.ustc.edu.cn/~lixuebai/GNU/Emacs.html emacs 用户配置文件

emacs tutorial 摘要

基本文本操作

获取帮助

C-h t 调出Tutorial C-h c C-h k (键盘命令) C-h f 查找(命令名) C-h a 查找 (关键字) C-h m 模式帮助 寻找快捷键 输入M-x method 就可知道此命令有否绑定的快捷键

execute method/function

Alt+x —-> M-x

配置文件.emacs生效

不退出emacs就让配置文件生效 M-x eval-buffer

光标移动

Unless you added a description to your link. Then, instead you should use the shortcut C-u C-c C-x C-v. Moving to top or end of the buffer M-< M-> C-v 向上滚屏;M-v 向下滚屏

上一行C-p

向后移C-b —向前移C-f

下一行C-n

向后移一词(中文一标点)M-b ;向前移一词(中文一标点)M-f Meta系命令――语言单位(词,句子,段落等) Ctrl系命令――与语言无关基本单位(字符,行等) C-a 行首 C-e 行尾 M-a 句首 M-e 句尾 数字参数,如C-u 8 C-b 向后移8个字符。 另外注意C-u 8 C-v表示向上滚8行而非8屏,C-n也是的。 C-g终止命令(如对一无法响应命令) 按错<ESC>,应该连按两次<ESC>;而<ESC><ESC><ESC>是通用的离开命令。 C-x 1保留一个窗口(光标所在的那个) <backspace> 删除前一个字符 C-d 删除后一个字符 M-<backspace> 移除前一个词 M-d 移除后一个词 C-k 移除到行尾的字符 M-d 移除到句尾的字符 C-@ Mark Set,然后挪动光标到需要的位置,C-w 移除 C-y 召回(yanking)最近一次的;M-y 召回(不断倒前) C-x u或者C-_表示Undo C-x C-f查找文件或者新建文件 C-x C-s 存储 C-x C-c 退出 每个打开的文件都在各自缓冲区中,C-x C-b列出缓冲区, 切换用C-x C-f查找的方式,或者C-x b回车然后输入buffer名字 C-x s 保存所有的未存盘的buffer C-z 暂时挂起emacs,调回用fg C-x 后面接字符扩展,而M-x后面接命令名扩展,如 字符串替换 M-x reply-string 恢复文件 M-x recover-file 自动折行 M-x auto-file-mode gnus M-x gnus dired M-x dired gdb M-x gdb 日历 M-x calendar shell mode M-x shell bbs M-x ansi-term M-s . search the word in cursor C-s 向前搜索; C-r 向后搜索 C-q 解除屏幕冻结 C-x 2 开两个窗口 C-M-v 向上滚动下一个窗口 C-M-Shift-v向下滚动下一个窗口 C-x o 切换光标到下一个窗口 C-x C-q 改变缓冲区的只读状态

quik tutirial

C-g #quit a partical entered command C-x C-c # end emacs session

C-x C-b #list buffer C-x b <Buffername> #swich to buffer by name C-x <- prev buffer C-x -> next buffer

C-x 2 #split the current windown into 2 C-x o #select another window C-x 0 #del current window

C-x 4 b <BUFNAME> # open a buffer in another window C-x C-o <filename> # open a fiel in another window

M-! <shell_comand> #run the shell command and diplay the output(`shell-commad’

C-x C-f #find a file C-x C-s #save C-/ # undo

evaluate a piece of Emacs Lisp code the code in between () in ”scratch” buffer, C-j to evaluate it (getenv “PATH”) (getenv “HOME”)

text eding

C-@ mark a point(then shift and arrow key to select a region)

copy and paste

C-w 剪切 #run the shell command and diplay the output(`shell-commad’ M-w 复制 C-y 粘贴

C-@ or C-<space> mark a point(then shift and arrow key to select a region)* C-w 剪切 kill a region C-k kill a line right of the rest of the cursor M-w 复制 C-y 粘贴

C-w ⇒ Cut (really kill) M-w ⇒ Copy (really kill-ring-save) C-y ⇒ Paste (really yank) M-y (after C-y) ⇒ Historic Paste of old cuts/copies “bonus” (really yank-pop, that is to say the kill-ring cometh)

block or region editing

select a region

C-x-<space> start to block mode marking, select the region

insert characters in the region

C-x r t, inserting character you want in all the region

M-x string-insert-rectangle <RET> STRING <RET>

operations on the region

C-w 剪切 kill a region M-w 复制 C-y 粘贴

emacs -nw // running in console

In term mode the normal prefix key for Emacs commands is C-c. It works pretty much like C-x prefix key elsewhere in Emacs. I prefer using C-x in term mode too so I do this in my ~/.emacs file:

(add-hook ‘term-mode-hook ‘(lambda () (term-set-escape-char ?\C-x)))

how to redefine a key of some command C-h k to search the command name C-@ help text C-@ runs the command set-mark-command, so in .emacs

(global-set-key (kbd “C-c ,”) ‘set-mark-command) ; Ctrl+c ,

In emacs, you can create any keyboard shortcut to any command. This page shows you how.

For example, if you want 【F9】 for calendar, then, place this code (global-set-key (kbd “<f9>”) ‘calendar) in your emacs init file and restart emacs.

If you are experimenting, and don’t want to restart emacs every time you try to define a new key, you can place cursor at the end of parenthesis and call eval-last-sexp 【Ctrl+x Ctrl+e】. The new key will be active right away.

保存和回复工作环境

(desktop-save-mode 1) M-x desktop-save-mode #will save the desktop when emacs quit M-x desktop-change-dir #will load the desktop file which has been saved M-x desktop-save #will save the desktop manually with the command M-x desktop-read #will read the desktop manually with the command

M-x describe-variable ret desktop-save-mode

编辑环境操作,对预设变量赋值

在emacs中,所有的操作都可以通过命令M+x commandname 完成 M x shell (进入某种模式)

取得某个变量的值

emacs的很多配置是通过改变预设变量的值来实现的 比如想要查看 fill-column的值, M x describe-variable (RET) Describe variable:fill-column

设置某个变量的值

M-x set-variable (RET) Set variable:fill-column(RET) ;;显示行号

~/.emacs 配置文件设置变量值

;;setq 设置变量的值 (column-number-mode t) (show-paren-mode t) ;;设置TAB宽度为4 (setq default-tab-width 4) 这里有的是数字,有的是bool设为t表示true的意思,

取得你喜欢的颜色值

在emacs的帮助和设置里可以把光标放到你喜欢的face上,用 M-x describe-face Describe face (default org-level-3):(RET) 来查看相应的字体,颜色名称,然后再用 M-x customize-face RET default RET

取得颜色主题

sudo apt-get install emacs-goodies-el

;;(add-to-list ‘load-path “~/.emacs.d/color-theme/”) #run the shell command and diplay the output(`shell-commad’ (require ‘color-theme) (eval-after-load “color-theme” ‘(progn (color-theme-initialize) (color-theme-xemacs))) 来设置相关的颜色。

对文件的操作dired模式

M-x dired invokes Dired, the file manager mode, on a directory of your choice. C-x C-q (or M-x wdired-change-to-wdired-mode) switches to Editable Dired mode: In this mode, changing the filenames in the right-hand column and then typing C-x C-s

自动补全功能

add and config the plugin

(add-to-list ‘load-path “~/.emacs.d/auto-complete-1.3.1”) (require ‘auto-complete-config) ;(add-to-list ‘ac-dictionary-directories “~/.emacs.d/ac-dict”) (add-to-list ‘ac-user-dictionary-files “/usr/share/dict/words”) (ac-config-default)

config i-spell-complete-word

(global-set-key [f9] ‘ispell-complete-word)

spell checking

M-x ispell-complete-word ##will complete M-x flyspell-mode ## will underline the wrong spelled words

字典功能。

aptitude安装dict-xdict, dictd, dictionary-el, 然后在.emacs中写 (setq dictionary-sever “localhost”) 若想在线http://www.dict.org 查词,便不用安装dictd

shell command mode 与 shell mode的区别

emacs有两种执行shell指令的方法,一种是进入shell command mode;另一种是 shell mode.两者都可以执行shell指令,起最大的不同之处是,进入shell mode 的状态,执行shell指令的同时,仍可以切换到其他模式处理别的工作,但如果使用shell command mode,则必须等指令完成之后才可以作其他的事情。 M-! 唤起shell-command mode M-x shell 唤起shell-mode eshell与shell mode的区别 test[fn:1] eshell是elisp写的shell,有全屏编辑器支持,理论上可作常规shell 做不到的事情,但实际上功能也一般了^_^ 打开文件依然是C-x C-f, eshell还可以ind file 另外,一些大一点的操作建议不要在eshell中实现,而应该在shell mode中,比如copy大一点的文件。

grep, compile,gdb,man

emacs 的寄存器

emacs 有多个寄存器,命名可以用一个character,比如1,c等,但只能一个字符 M-x list-registers copy-rectangle-to-register C-x r r Copy rectangular region into register REGISTER. copy-to-register C-x r s, C-x r x Copy region into register REGISTER. insert-register C-x r i, C-x r g Insert contents of register REGISTER. (REGISTER is a character.)

Emacs 寄存器

C-x r SPC (寄存器名)M-x point-to-register 存贮光标位置
C-x r w (寄存器名)M-x window-configuration-to-register 保存当前窗口状态
C-x r f (寄存器名)M-x frame-configuration-to-register 保存所有窗口状态
C-x r j (寄存器名)M-x jump-to-register 光标跳转
C-x j (寄存器名)略…… 同上

列块编辑模式

在emacs下进行列编辑,之前多次用到,但都是现查现用,过了就把快捷键又忘了,今天索性记在这里,省得下次又满世界查快捷键。

  1. 选择区域, 和普通的emacs 操作一样用 C-@ 选择高亮一块区域,注意最后光标的停留位置和初始位置之间必须是有列的差值的,简言之,起始光标位置和终止光标位置不在同一列
  2. 后续可选操作
    • 在这块区域插入空白的方格, 用C-x r o
    • 删除这块区域用 C-x r d (这种删除掉之后不留空白)
    • 删除区域 C-x r C (删掉之后原位置保留为空)
    • 复制并删除这块区域用 C-x r k
    • 粘贴刚才C-x r k复制的区域用C-x r y
    • 用字符替换选中区域用C-x r t

复杂操作:

  • C-x r r copy-rectangle-to-register
  • 将选定的矩形区域复制到某个寄存器
  • 选中去区域后 C-x r r 将选中区域复制到寄存器,在输入这组键后命令栏会等待你输入寄存器号,这时随便输入一个数字即可,不过的记得它,因为待会儿粘贴的时候还得用到这个寄存器号。我刚开始就是被这个寄存器号搞得头晕,半天没弄明白是什么意思,现在理解这不过是对操作的区域做一个编号,待会在操作时比如复制时可以根据这个号码选择之前操作的区域。
  • C-x r i 插入寄存器的内容,输入此键后再输入寄存器号可将寄存器中的内容插入到当前区域。

关于org模式

overal key

TAB#FOLDED -> CHILDREN -> SUBTREE
Shift-TABOVERVIEW -> CONTENTS -> SHOWALL
C-u C-u C-u TABshowall

org模式的激活

编辑的文件名为.org后缀的直接进入org模式

;; emacs 的load-path变量存有所有插件的变量路径 ;; auto-mode-alist auto-mode-alist 如果设置为 nil,那么将关闭根据文件名扩展自动选择主要模式的功能。 它的缺省值是一些文件名扩展和相应模式的列表。 (add-to-list ‘load-path “~/org-7.7”) (require ‘org) (add-to-list ‘auto-mode-alist ‘(“\.org$” . org-mode)) (define-key global-map “\C-cl” ‘org-store-link) (define-key global-map “\C-ca” ‘org-agenda) (setq org-log-done t)

文件第一行用一下方式也可以标识文件进入org模式n

emacs projects -*- mode: org; -*-

org模式的颜色customize

M-x customize-group RET org-faces RET 来定义各级菜单字体的颜色、背景颜色等。当然,Org Mode 的定义有点特殊,对于普通的文字设置,需要通过

M-x customize-face RET default RET 来对 Emacs 全文的普通字体来进行设置。

org的常用命令

目录树

Emacs建立目录树是很简单的。使用* 3就可以了。一级是一个*,二级是两个*,以此类推。当你导出以后会自动 的生成目录链接。 在Emacs里面使用Shift+Tab键可以收起所有的目录树,再按Tab可以依次展开。 Alt+左右方向键是减少/增加当前节点的层级.Alt+Shift+左右方向键 可以将效果作用到子节点上。Alt+上下键可以移动节点。

Tag

当目录树的节点越来越多时,查找就不方便了,这时候可以给节点添加Tag。光标到节点上,Ctrl+c两次, 就会提醒你输入tag添加即可。要查询tag,Ctrl+c \ 就可以了。 files/03.png

链接

./pic/curev.jpg[picture desciption]] 链接格式[[link][]] 后面的中括号内是description可以省略 按下Ctrl+c Ctrl+l就可以添加一个链接,可以链接任何文件。只要输入绝对路径或相对路径即可。 对于图片来说,如果不给图片添加描述的话,在导出的时候,Emacs会自动显示图片,如果添加了描述则是超链接形式了。

display the link in plain text

M-x font-lock-mode

display the inline image link

C-c C-x C-v (org-toggle-inline-images) Unless you added a description to your link. Then, instead you should use the shortcut C-u C-c C-x C-v.

display inline image link with command

the global command M-x org-display-inline-images.

Always display inline images in all Org files

Add this line to your Emacs configuration file. It tells Emacs that each time you open an Org file it must display the images instead of its link.

(setq org-startup-with-inline-images t)

If you use this setting and don’t want to see images in a specific file, add this at the top of the org files that are not to display images:

Display inline images in selected Org files only

On the contrary, if you always want to see images save in specific org files:

Don’t add the setq instruction we just saw Add this line at the top of each file for which you want Emacs to display its images:

脚注

Ctrl+c Ctrl+x f会自动给光标处添加一个脚注。我已经在上面添加了几个脚注了。添加完脚注,再按一次Ctrl+c Ctrl+x f就会回到原来添加脚注的地方。

表格

Emacs添加表格很方便。输入使用|分隔即可。多试试Tab键就知道了。下面看看效果。 emacs把第一行以|开头的行认做表格

NamePhoneAge

1—————————–

NamePhoneAge

2—————————–

NamePhoneAge
Peter1233980813
Anna68908733

3——————————–

这里从1到2步只需键入tab键就可以了 2到3步输入文本按tab会自动对齐

Write a letter to Don

可以做计划列表,名字特定为TODO,全部大写。

时间控制 Ctrl+c Ctrl+s 插入计划时间,Ctrl+c Ctrl+d插入最后时间,Ctrl+c .插入时间戳 多选任务列表 [50%]

  • [] 就是一个多选按钮了,在这一行按两次Ctrl+c就会选中此项。再按两次取消。在节点上加入[%]就会按照半分比来显示完成情况。[/]按照数量来显示完成情况。自己试试吧。
  • [X] 第二个多选按钮,选中了。

org export to html

M-x org-export-as-html-and-open will export current org file into a html file and open it in emacs

M-x org-export-as-html will be the same name as org file, but suffix is .html will be saved

浏览代码

ctags 查看源代码

ctags -e -R 生成emacs认识的tag表,用-e 使用快捷键: M-x visit-tags-table 指定TAGS文件 M-. 查找一个tag,比如函数定义类型定义等。 C-u M-. 查找下一个tag的位置 C-M-. 输入函数名,查找定义 M-* 回到上一次运行M-.前的光标位置。 M-TAB 自动补齐函数名(M可用ESC代替)

grep查找

M-x grep 例如在一个工程里查找函数名就schedule的函数的定义以及引用, grep -n -e schedule -r –include=*.[hc] .

gnus模式

emacs23自带gnus模式,

用gnus收邮件

显示邮件列表

在group buffer里,用L 显示邮件组合: nnfolder:mail.misc (~/Mail/mail/misc) //misc 是个文件,所有邮件都压缩在里边 nnml:mail.misc、 (~/Mail/mail/misc) //misc 是个目录 如果没有显示可用^进入server buffer U订阅邮件服务器 如果不想看新闻组,可以用M-x gnus-no-server 光标在上边用M-g 可以刷新邮箱

  • 2、启动:m-x gnus
  • 3、看是否有新邮件:g
  • 4、发邮件:m,增加附件,c-c c-a,写完c-c c-c,转发邮件:c-c,c-f
  • 5、订阅邮件服务器:U,然后输入服务器名称,取消订阅也一样。
  • 保存附件:光标在附件名称上按o
  • 6、去掉服务器:c-k
  • 7、保存有价值的帖子:在.gnus.el文件中加这一句 (setq gnus-use-cache ‘passive),然后在有价值的帖子上加*,就保存到本地,按meta+*就取消保存
  • 8、利用gnus订阅rss
  • 在gnus总目录下:G R,然后根据提示输入URL,其中URL的格式是这样的:http://www.wanglianghome.org/blog/rss.xml 或者这样:http://feed.feedsky.com/jaylee
  • 9、对邮件进行排序:
  • 默认排序的方式是按照时间排序, 在 summary buffer 中 C-h m ,很容易找到
  • C-c C-s TAB gnus-summary-sort-by-score
  • C-c C-s C-d gnus-summary-sort-by-date
  • C-c C-s C-s gnus-summary-sort-by-subject
  • C-c C-s C-a gnus-summary-sort-by-author
  • C-c C-s C-c gnus-summary-sort-by-chars
  • C-c C-s C-l gnus-summary-sort-by-lines
  • C-c C-s C-n gnus-summary-sort-by-number

查找 所有 邮件内容

很多邮件的客户端程序都没有做到这点,其实用grep命令就可以搜索到 grep -nH “pattern” misc 找到后查看此邮件的subject,可以在邮件列表中找到这个subject的邮件 有时因为编码问题grep查找中文会有问题,因为一般是GBK编码,grep 用utf-8,所以可以用enca转换后查找 enca -x utf-8 <110 |grep 莉莉 ./pic/chinese-encoding]

这基本上是使用gnus查看邮件的主要原因

删除邮件

在buffer区,光标所在处 B-<delete> 用`E’命?,给新闻组里的帖子加上expirable的标签 (setq nnmail-expiry-wait 3) 样就把保质期设成3天了。

Footnotes

[fn:1] test for footnots

lisp programming—

In my .emacs i have the following function that transposes a line

(defun move-line (n) “Move the current line up or down by N lines.” (interactive “p”) (let ((col (current-column)) start end) (beginning-of-line) (setq start (point)) (end-of-line) (forward-char) (setq end (point)) (let ((line-text (delete-and-extract-region start end))) (forward-line n) (insert line-text) ;; restore point to original column in moved line (forward-line -1) (forward-char col)))) And I bind a key to it like this

(global-set-key (kbd “M-<down>”) ‘move-line) ;; this is the same as M-x global-set-key <return> However, I want to bind M-up to move-line (-1) But I cant seem to be able to do it correctly:

;; M– M-1 M-x global-set-key <return> How do I define the above using global-set-key to call move-line -1?

emacs elisp share|improve this question asked Jun 23 ‘09 at 2:33

yrral 19617 5 Just FYI: there is a transpose-lines function built into emacs. Try shortcut C-x C-t. – polyglot Jun 23 ‘09 at 4:05 add comment 3 Answers activeoldestvotes up vote 13 down vote accepted Not minutes after asking the question I figured it out by copy+pasting code. However I have no clue how it works.

(global-set-key (kbd “M-<up>”) (lambda () (interactive) (move-line -1)))


M-x g M-x g M-x g linenumber

M-x linum-mode # display linenumber M-x ffap #vim gf M-x compilation-mode ##make the filename line make a link to jump,like lopen

M-x grep <RET> keyword <filename> M-p C-<UP> Fetch the next earlier old shell command.

switch minor mode M-x evil-mode ###would toggle this mode on and off

####################### w3m shift-B #previous page Tab #next link Shift-U #URL prompt Shift-H #help Shift-T #open a new tab { } #switch between tabs g #open URL R #Reload buffer c #peek current URL

##################################

Here is etags2ctags.el. It converts Emacs TAGS files generated by etags to what look like ex/vi tags files generated by ctags. I’m not sure how useful this is, but I while ago I decided it was for some reason and put it on my list. I had initially thought of doing it in C; but it occurred to me that it would be much easier to do in Emacs lisp, and I was surprised at how little code it took.

Enjoy!

;;; Convert Emacs TAGS files (the output of the `etags’ program) ;;; to ex/vi tags files (like the output of the `ctags’ program). ;;; ;;; Copyright (C) 1989 Roland McGrath ;;; ;;; This program is free software; you can redistribute it and/or modify ;;; it under the terms of the GNU General Public License as published by ;;; the Free Software Foundation; either version 1, or (at your option) ;;; any later version. ;;; ;;; This program is distributed in the hope that it will be useful, ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;; GNU General Public License for more details. ;;; ;;; A copy of the GNU General Public License can be obtained from this ;;; program’s author (send electronic mail to ky…@cs.odu.edu) or from ;;; the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA ;;; 02139, USA. ;;; ;;; Send bug reports to rol…@ai.mit.edu.

;; To use this, byte-compile this file, and then put the following line ;; in your .emacs (or site-init.el, etc.): ;; (autoload ‘etags2ctags-buffer “etags2ctags” “Convert a TAGS buffer.” t) ;; (autoload ‘etags2ctags-file “etags2ctags” “Convert a TAGS file.” t)

(defmacro match-text (arg) “Return the string of text matched by the last regexp searched for. ARG, a number, specifies which parenthesized expression in the last regexp. The value is nil if ARGth pair didn’t match, or there were less than ARG pairs. Zero means the entire text matched by the whole regexp.” (` (buffer-substring (match-beginning (, arg)) (match-end (, arg)))))

(defun etags2ctags-buffer (&optional buffer) “Convert output from `etags’ in BUFFER to what looks like output from `ctags’. If BUFFER is nil or missing, the current buffer is used.” (interactive “bConvert buffer: “) (save-excursion (if buffer (set-buffer buffer)) (goto-char (point-min)) ;; We will write output into the temporary buffer ;; and then move it to BUFFER all at once. (let ((standard-output (generate-new-buffer ” etags2ctags”))) (while (not (eobp)) (or (looking-at “\f\n”) (error “Invalid tags file format”)) (forward-line 1) (let ((file (buffer-substring (point) (progn (search-forward “,”) (1- (point))))) (end (let ((len (string-to-int (buffer-substring (point) (progn (forward-line 1) (point)))))) (+ (point) len)))) (while ;; This monster regexp matches an etags tag line. ;; \1 is the string to match; ;; \2 is not interesting; ;; \3 is the symbol; ;; \4 is the char to start searching at; ;; \5 is the line to start searching at. (re-search-forward “^\(\(.+[ \t]+\)?\([-a-zA-Z0-9_$]+\)[^-a-zA-Z0-9_$]*\)\^?\([0-9]+\),\([0-9]+\)\n” end t) ;; Turn the matched etags tag line into the ctags tag line: ;; FILE SYMBOL ^STRING ;; The string is regexp-quoted. (princ (regexp-quote (match-text 3))) (princ “\t”) (princ file) (princ “\t/^”) (princ (regexp-quote (match-text 1))) (princ “/”) (terpri) ))) ;; Sort the temporary buffer. (save-excursion (set-buffer standard-output) (sort-lines nil (point-min) (point-max))) ;; Replace the contents of BUFFER with those of the temporary buffer. (undo-boundary) (erase-buffer) (insert-buffer standard-output) (kill-buffer standard-output) )))

(defun etags2ctags-file (from to) “Convert the Emacs TAGS file in FROM to a ex/vi tags file in TO. See etags2ctags-buffer .” (interactive “fConvert Emacs TAGS file: \nFConvert %s to ex/vi tags file: “) (let ((buf (generate-new-buffer ” etags2ctags”))) (save-excursion (set-buffer buf) (insert-file from) (etags2ctags-buffer buf) (write-file to) (kill-buffer buf) ))) ##################################################

etags and usage

generate etags:

find . -type f -iname “*.[ch]” |etags - find . -ypte f -iname “*.[ch]” |xargs etags –append


M-: Read a single Lisp expression in the minibuffer, evaluate it, and print the value in the echo area (eval-expression). C-x C-e Evaluate the Lisp expression before point, and print the value in the echo area (eval-last-sexp). C-M-x Evaluate the defun containing or after point, and print the value in the echo area (eval-defun). M-x eval-region Evaluate all the Lisp expressions in the region. M-x eval-current-buffer Evaluate all the Lisp expressions in the buffer.

group buffer: ibuffer

########################## here you can define your buffer groups. You can mark buffers, use filtering and sorting, do search/replace in marked buffers and other useful stuff.

For your case just put into the hook (ibuffer-filter-by-filename “.”)

Here is an example from my .emacs .

(require ‘ibuffer)

(setq ibuffer-saved-filter-groups (quote ((“default” (“dired” (mode . dired-mode)) (“java” (mode . java-mode)) (“org” (mode . org-mode)) (“sql” (mode . sql-mode)) (“xml” (mode . nxml-mode))))))

(setq ibuffer-show-empty-filter-groups nil)

(add-hook ‘ibuffer-mode-hook (lambda () (ibuffer-switch-to-saved-filter-groups “default”) (ibuffer-filter-by-filename “.”))) ;; to show only dired and files buffers EDIT. If you want to filter out temporary buffers (which name begins with *) you can set the following filter (regex)

(ibuffer-filter-by-name “^[^*]”) It says that the buffer name should start with any character except *.

no wrap line enable To enable it globally, there is a global-visual-line-mode which you would enable with M-x global-visual-line-mode.

To enable it as a file variable, it??d be -*- mode:blah ; mode:visual-line -*-.

If you don??t want to use the visual-line-mode command because you don??t want the behaviors changed (i.e., you want it to leave your C-a, C-e pure), the variable to set is ??word-wrap??: i.e., M-: (setq word-wrap t), or placing it as a file variable -*- mode:blah ; word-wrap:t -*- in your first line.

Usage of the word-wrap feature is really dependent on whether or not you like to horizontally scroll or not (with ??truncate-lines??). I don??t, since I??m

debug php using genben in emacs

URL https://blogs.oracle.com/opal/entry/quick_debugging_of_php_scripts

Quick Debugging of PHP Scripts in Emacs with Geben and Xdebug By cj on Jan 23, 2013

When you want to test a PHP code snippet quickly, it’s handy to do it within your day-to-day environment. For me, this environment is Emacs. The geben package for Emacs provides an interface to the DBGp protocol, such as used by Derick Rethans’s standard Xdebug extension for PHP.

With the combination of geben and Xdebug, I can quickly and efficiently step through execution of local files, examining code flow and data values.

Working steps to install and use the debugger on command line PHP scripts are shown below. They are standard enough that they can be customized to your actual environment.

You probably already have Xdebug installed, since it is the common debugger and profiler used by most IDEs. Installing geben in Emacs is straight forward.

  1. Download PHP 5.4 from http://php.net/downloads.php
  2. Install PHP with:

$ tar -jxf php-5.4.11.tar.bz2 $ cd php-5.4.11 $ ./configure –prefix=/home/cjones/php54 $ make install $ cp php.ini-development /home/cjones/php54/lib/php.ini

  1. Download the source code for the Xdebug Debugger extension for PHP from http://xdebug.org/download.php
  2. Install Xdebug into PHP with:

$ cd /home/cjones $ tar -zxf xdebug-2.2.1.tgz $ cd xdebug-2.2.1 $ export PATH=/home/cjones/php54/bin:$PATH $ phpize $ ./configure –enable-xdebug –with-php-config=/home/cjones/php54/bin/php-config $ make install

More information is shown in http://xdebug.org/docs/install

  1. Edit /home/cjones/php54/lib/php.ini and enable Xdebug by adding these lines:

zend_extension=/home/cjones/php54/lib/php/extensions/no-debug-non-zts-20100525/xdebug.so xdebug.remote_enable=on xdebug.remote_host=127.0.0.1

  1. Install geben manually or use the Emacs 24 package repository (M-x package-list-packages)

To manually install geben, download it from http://code.google.com/p/geben-on-emacs/downloads/list and install it with:

$ cd /home/cjones $ tar -zxf geben-0.26.tar.gz

  1. Add the following to the Emacs initialization file home/cjones.emacs. When testing this blog post, my .emacs file only contained this code:

(setq load-path (cons “/home/cjones/geben-0.26” load-path))

(autoload ‘geben “geben” “DBGp protocol frontend, a script debugger” t)

;; Debug a simple PHP script. ;; Change the session key my-php-54 to any session key text you like (defun my-php-debug () “Run current PHP script for debugging with geben” (interactive) (call-interactively ‘geben) (shell-command (concat “XDEBUG_CONFIG=’idekey=my-php-54’ /home/cjones/php54/bin/php ” (buffer-file-name) ” &”)) )

(global-set-key [f5] ‘my-php-debug)

Experienced Emacs users will most likely use local-set-key in a php-mode hook to set a key mapping.

  1. Start Emacs and load a PHP file:

$ emacs my.php

  1. Press F5 to start the debugger. The script will open in geben mode and can be stepped through with the space bar.

Geben mode commands can be shown with ‘?’. They include ‘v’ for showing variables, ‘c’ for run-to-cursor, and ‘g’ for completing the program.

Geben can also be used for scripts called via a browser. Start the geben listener in Emacs with M-x geben and load a script in the browser, passing an Xdebug URL parameter setting the session name. This initiates the debug session in Emacs. E.g. Load http://localhost/my.php?XDEBUG_SESSION_START=my-php-54

  1. When you are finished debugging, stop the debug server listener inside Emacs:

M-x geben-end

debug lisp

M-x debug-on-entry RET <functionname> RET evaluating the following in scratch buffer: (<functionname> <arg>) ctrl+j

d step into a line c jump to another <function> setting by debug-on-entry l list the <functions> set by debug-on-entry