lundi 31 mai 2010

Linux下如何查看CPU信息, 包括位数和多核信息


查看当前操作系统内核信息
# uname -a

Linux redcat 2.6.31-20-generic #58-Ubuntu SMP Fri Mar 12 05:23:09 UTC 2010 i686 GNU/Linux


查看当前操作系统发行版信息

#cat /etc/issue
Ubuntu 9.10 \n \l

查看cpu型号

# cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c
2 Intel(R) Core(TM)2 Duo CPU P8600 @ 2.40GHz
(看到有2个逻辑CPU, 也知道了CPU型号)

查看物理cpu颗数

# cat /proc/cpuinfo | grep physical | uniq -c

2 physical id : 0
(说明实际上是1颗2核的CPU)


查看cpu运行模式

# getconf LONG_BIT

32

(说明当前CPU运行在32bit模式下, 但不代表CPU不支持64bit)


查看cpu是否支持64bit

# cat /proc/cpuinfo | grep flags | grep ' lm ' | wc -l

2

(结果大于0, 说明支持64bit计算. lm指long mode, 支持lm则是64bit)


查看cpu信息概要(昨天看aix的时候刚发现的,在ubuntu上竟然也有~):

#lscpu

Architecture: i686 #架构686
CPU(s): 2 #逻辑cpu颗数是2
Thread(s) per core: 1 #每个核心线程数是1
Core(s) per socket: 2 #每个cpu插槽核数/每颗物理cpu核数是2
CPU socket(s): 1 #cpu插槽数是1
Vendor ID: GenuineIntel #cpu厂商ID是
GenuineIntel
CPU family: 6 #cpu系列是6
Model: 23 #型号23
Stepping: 10 #步进是10
CPU MHz: 800.000 #cpu主频是800MHz
Virtualization: VT-x #cpu支持的虚拟化技术VT-x(对此在下一博文中解释下http://hi.baidu.com/sdusoul/blog/item/5d8e0488def3a998a5c272c0.html)
L1d cache: 32K #一级缓存32K(google了下,这具体表示表示cpu的L1数据缓存为32k)
L1i cache: 32K
#一级缓存32K(具体为L1指令缓存为32K)
L2 cache: 3072K #二级缓存3072K

最后来个大而全的:

#cat /proc/cpuinfo

processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 23
model name : Intel(R) Core(TM)2 Duo CPU P8600 @ 2.40GHz
stepping : 10
cpu MHz : 800.000
cache size : 3072 KB
physical id : 0
siblings : 2
core id : 0
cpu cores : 2
apicid : 0
initial apicid : 0
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm constant_tsc arch_perfmon pebs bts pni dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm sse4_1 xsave lahf_lm ida tpr_shadow vnmi flexpriority
bogomips : 4788.60
clflush size : 64
power management:

processor : 1
vendor_id : GenuineIntel
cpu family : 6
model : 23
model name : Intel(R) Core(TM)2 Duo CPU P8600 @ 2.40GHz
stepping : 10
cpu MHz : 800.000
cache size : 3072 KB
physical id : 0
siblings : 2
core id : 1
cpu cores : 2
apicid : 1
initial apicid : 1
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm constant_tsc arch_perfmon pebs bts pni dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm sse4_1 xsave lahf_lm ida tpr_shadow vnmi flexpriority
bogomips : 4787.96
clflush size : 64
power management:

.bashrc 20100531

# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# If not running interactively, don't do anything
[ -z "$PS1" ] && return

# don't put duplicate lines in the history. See bash(1) for more options
# don't overwrite GNU Midnight Commander's setting of `ignorespace'.
HISTCONTROL=$HISTCONTROL${HISTCONTROL+,}ignoredups
# ... or force ignoredups and ignorespace
HISTCONTROL=ignoreboth

# append to the history file, don't overwrite it
shopt -s histappend

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi

# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color) color_prompt=yes;;
esac

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi

if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
;;
*)
;;
esac

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
#alias dir='dir --color=auto'
#alias vdir='vdir --color=auto'

alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'

#Renote Desktop Viewer
alias i11m='rdesktop -g 90% -a 16 -u "ma wei" -0 156.18.40.219'
alias i11b='rdesktop -g 90% -a 16 -u "MA" -0 156.18.40,236'

alias iorn='ssh -X fang@hurricane.mecaflu.ec-lyon.fr'
alias jma='ssh -X mawei@156.18.38.239'

#
alias ll='ls -l'
alias la='ls -A'
alias l='ls -CF'

#tecplot
alias tecplot='tec360 -mesa'

#veusz
alias veusz='veusz_main.py'
#emacs for chinese input
alias emacs='LANG=zh_CN.UTF-8 emacs'
fi

# some more ls aliases
#alias ll='ls -l'
#alias la='ls -A'
#alias l='ls -CF'

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
. /etc/bash_completion
fi

#export PS1="\[\033[0;37;44m\u@\033[0;32;43m\h:\033[0;33;41m\w$\033[0m\]"

BLUE=`tput setf 1`
GREEN=`tput setf 2`
CYAN=`tput setf 3`
RED=`tput setf 4`
MAGENTA=`tput setf 5`
YELLOW=`tput setf 6`
WHITE=`tput setf 7`
PS1='\[$GREEN\]\u@\h \[$BLUE\]\w\[$GREEN\] \$\[$WHITE\] '

export PATH=/opt/tecplot/bin:$PATH
export PATH=/opt/intel/Compiler/11.1/064/bin/ia32:$PATH
export PATH=/opt/fluent/Fluent.Inc/bin:$PATH
export PATH=/opt/veusz-1.6:$PATH
export PATH=/opt/matlab/bin:$PATH
#begin NUMECA configuration
PATH=/usr/local/numeca/bin:${PATH}
export PATH
#end NUMECA configuration

jeudi 20 mai 2010

freefem fipy

freefem 2d
fipy 3d

dimanche 9 mai 2010

.emacs 20100509

(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(blink-cursor-mode nil)
)
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)

;;-----------------------------------------------------------------------------
;; to enable highlighting when searching
(setq search-highlight t)
;;to highlight matches when using serch-and-replace
(setq query-replace-highlight t)
;;用win+space为set-mark键,留出ctrl+space热键作为输入法
(global-set-key (kbd "C-SPC") 'nil)
(global-set-key (kbd "s-SPC") 'set-mark-command)
;;设置字体大小
(set-default-font "DejaVu Sans Mono-8")
;;在窗口左侧显示行号
(global-linum-mode t)
;;在状态栏(mode line)上显示行号
(setq column-number-mode t)
(setq line-number-mode t)
;;鼠标自动避开指针,如当你输入的时候,指针到了鼠标的位置,鼠标有点挡住视线了
(mouse-avoidance-mode 'animate)
;;指针不要闪
(blink-cursor-mode -1)
(transient-mark-mode 1)
;;当指针到一个括号时,自动显示所匹配的另一个括号
(show-paren-mode 1)
;;去掉烦人的警告铃声
(setq visible-bell nil)
;;去掉Emacs和gnus启动时的引导界面
(setq inhibit-startup-message t)
(setq gnus-inhibit-startup-message t)
;; 显示时间
(setq display-time-24hr-format t)
(setq display-time-day-and-date t)
(display-time)
;;当前行高亮
(require 'hl-line)
(global-hl-line-mode t)
;;滚动条在窗口右侧
'(scroll-bar-mode (quote right))
;;在窗口的标题栏上显示文件名称
(setq frame-title-format "%n%F/%b")
;;允许emacs和外部其他程序的粘
(setq x-select-enable-clipboard t)
;;支持中键粘贴
(setq mouse-yank-at-point t)
;;所有的问题用y/n方式,不用yes/no方式
(fset 'yes-or-no-p 'y-or-n-p)
;;go-line快捷键
(global-set-key (kbd "M-g") 'goto-line)
;; 在行首 C-k 时,同时删除该行。
(setq-default kill-whole-line t)
;;保存前,删除当前buffer中行尾空格和TAB等whitespace
(add-hook 'before-save-hook 'delete-trailing-whitespace)
;;(setq ansi-color-for-comint-mode t)使用shell,shell中没有乱码
(ansi-color-for-comint-mode-on)
;;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
;; Add the directories to your load path
(add-to-list 'load-path "~/.emacs.d/")
;;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
;;------------------------------------------------------------------------------
;; 启动时的屏幕大小
;;第一种方法,需要根据不同的电脑屏幕大小进行修正
;;第二种方法,思路很好,但是垂直方向(vert)超过了显示范围,需要修正
;;------------------------------------------------------------------------------
;;第一种方法
(setq default-frame-alist
(append '((top . 0)(left . 0)(width . 175)(height . 45))
default-frame-alist))
;;第二种方法
;(defun my-maximized-horz ()
; (interactive)
; (x-send-client-message
; nil 0 nil "_NET_WM_STATE" 32
; '(1 "_NET_WM_STATE_MAXIMIZED_HORZ" 0)))
;(defun my-maximized-vert ()
; (interactive)
; (x-send-client-message
; nil 0 nil "_NET_WM_STATE" 32
; '(1 "_NET_WM_STATE_MAXIMIZED_VERT" 0)))
;(defun my-maximized ()
; (interactive)
; (x-send-client-message
; nil 0 nil "_NET_WM_STATE" 32
; '(1 "_NET_WM_STATE_MAXIMIZED_HORZ" 0))
; (interactive)
; (x-send-client-message
; nil 0 nil "_NET_WM_STATE" 32
; '(1 "_NET_WM_STATE_MAXIMIZED_VERT" 0)))
;(my-maximized)
;;-----------------------------------------------------------------------------
;; cursor-chg.el
;;-----------------------------------------------------------------------------
(require 'cursor-chg) ; Load this library
(change-cursor-mode 1) ; On for overwrite/read-only/input mode
(toggle-cursor-type-when-idle 1) ; On when idle
;;-----------------------------------------------------------------------------
;;调用smart-compile
;;-----------------------------------------------------------------------------
(require 'smart-compile)
(global-set-key [f7] 'smart-compile)
;;-----------------------------------------------------------------------------
;; add emacs-wiki
;;-----------------------------------------------------------------------------
;; Add the directories to your load path
;(add-to-list 'load-path "~/.emacs.d/emacs-wiki-2.72")
;;调用emacs-wiki
;(require 'emacs-wiki)
;(require 'emacs-wiki-menu)
;(load "emacs-wiki")
;;----------------------------------------------------------------------------
;; 调用tabbar,在head中显示打开文件列表
;;-----------------------------------------------------------------------------
(require 'tabbar)
(tabbar-mode t)
;;全部分在同一组
(setq tabbar-buffer-groups-function
(lambda ()
(list "All")))
;;----------------------------------------------------------------
;; add a buffer modification state indicator in the tab label,
;; and place a space around the label to make it looks less crowd
;;----------------------------------------------------------------
(defadvice tabbar-buffer-tab-label (after fixup_tab_label_space_and_flag activate)
(setq ad-return-value
(if (and (buffer-modified-p (tabbar-tab-value tab))
(buffer-file-name (tabbar-tab-value tab)))
(concat " + " (concat ad-return-value " "))
(concat " " (concat ad-return-value " ")))))
;; called each time the modification state of the buffer changed
(defun ztl-modification-state-change ()
(tabbar-set-template tabbar-current-tabset nil)
(tabbar-display-update))
;; first-change-hook is called BEFORE the change is made
(defun ztl-on-buffer-modification ()
(set-buffer-modified-p t)
(ztl-modification-state-change))
(add-hook 'after-save-hook 'ztl-modification-state-change)
;; this doesn't work for revert, I don't know
;;(add-hook 'after-revert-hook 'ztl-modification-state-change)
(add-hook 'first-change-hook 'ztl-on-buffer-modification)
;;----------------------------------------------------------------------------
;; 使用一个简单的 Elisp 函数
;;:如果选定了区域,那么按 M-w 就复制这个区域;如果没有选定区域,那么 M-w 就复制一行
;;-----------------------------------------------------------------------------
(defun huangq-kill-ring-save (&optional n)
"If region is active, copy region. Otherwise, copy line."
(interactive "p")
(if mark-active
(kill-ring-save (region-beginning) (region-end))
(if (> n 0)
(kill-ring-save (line-beginning-position) (line-end-position n))
(kill-ring-save (line-beginning-position n) (line-end-position)))))

(global-set-key (kbd "M-w") 'huangq-kill-ring-save)

;;-----------------------------------------------------------------------------
;;备份设置
;;-----------------------------------------------------------------------------
;;emacs还有一个自动保存功能,默认在~/.emacs.d/auto-save-list里,
;;这个非常有用,具体可以参见Sams teach yourself emacs in 24hours(我简称为sams24)
;;启用版本控制,即可以备份多次
(setq version-control t)
;;备份最原始的版本两次,记第一次编辑前的文档,和第二次编辑前的文档
(setq kept-old-versions 2)
;;备份最新的版本五次,理解同上
(setq kept-new-versions 5)
;;删掉不属于以上7中版本的版本
(setq delete-old-versions t)
;;设置备份文件的路径
(setq backup-directory-alist '(("." . "~/.emacs.tmp")))
;;备份设置方法,直接拷贝
(setq backup-by-copying t)
;;-----------------------------------------------------------------------------
;; 快速在另外一个buffer中打开shell并cd 到当前 buffer 所在的目录
;;-----------------------------------------------------------------------------
(defun kid-switch-to-shell ()
(interactive)
(when (null (cdr (window-list)))
(split-window-horizontally))
(let ((file buffer-file-name))
(other-window 1)
(shell)
(when file
(end-of-buffer)
(when (looking-back shell-prompt-pattern)
(insert "cd " (file-name-directory file))
(call-interactively 'comint-send-input)))))
(global-set-key (kbd "") 'kid-switch-to-shell)
;;-----------------------------------------------------------------------------
;; occur
;;-----------------------------------------------------------------------------
(defun occur-fortran ()
(interactive )
(setq mawei "\\(?:\\\\|\\\\|\\\\|\\\\|\\\\|\\\\)")
(occur mawei)
;(occur (regexp-opt '("program""subroutine""function""call")))
)
(global-set-key (kbd "") 'occur-fortran)
;;-----------------------------------------------------------------------------
;; 每当我在 M-x shell启动shell,然后执行 exit 退出 shell 之后,buffer 并不自动关闭,很不爽,
;; 下面的指令,可以让其自动关闭。
;;-----------------------------------------------------------------------------
(add-hook 'shell-mode-hook 'wcy-shell-mode-hook-func)
(defun wcy-shell-mode-hook-func ()
(set-process-sentinel (get-buffer-process (current-buffer))
#'wcy-shell-mode-kill-buffer-on-exit)
)
(defun wcy-shell-mode-kill-buffer-on-exit (process state)
(message "%s" state)
(if (or
(string-match "exited abnormally with code.*" state)
(string-match "finished" state))
;(kill-buffer (current-buffer))))
(kill-buffer-and-window )))
;;-----------------------------------------------------------------------------
;; 当前buffer的文件名,前加“./”,后去掉后面4位数字,输入到minibuffer
;;-----------------------------------------------------------------------------
;(define-key minibuffer-local-map [f8]
;(lambda ()
;(interactive)
;(insert (concat "./") )
;(insert (substring (buffer-name (current-buffer-not-mini)) 0 -4 ))
;(insert (concat ".exe") )
;)
;)
;
;(defun current-buffer-not-mini ()
;"Return current-buffer if current buffer is not the *mini-buffer*
;else return buffer before minibuf is activated."
;(not (window-minibuffer-p)) (current-buffer)
;(if (eq (get-lru-window) (next-window))
;(window-buffer (previous-window)) (window-buffer (next-window))))

;;------------------------------------------------------------------------------
;; auto-complete
;; -----------------------------------------------------------------------------
;; Add the directories to your load path
(add-to-list 'load-path "~/.emacs.d/")
(require 'auto-complete)
(global-auto-complete-mode t)
;; Use C-n/C-p to select candidates
;;(define-key ac-complete-mode-map "\M-n" 'ac-next)
;;(define-key ac-complete-mode-map "\M-p" 'ac-previous)
;; you can stop completion by pressing M-/.
;;(define-key ac-complete-mode-map "\M-TAB" 'ac-stop)
;; Completion by TAB
;;
;; Add following code to your .emacs.
;;
(define-key ac-complete-mode-map "\t" 'ac-complete)
(define-key ac-complete-mode-map "\r" nil)
;; Do What I Mean mode
;; -------------------
;;
;; If DWIM (Do What I Mean) mode is enabled,
;; the following features is available:
;;
;; a. TAB (ac-expand) behave as completion (ac-complete)
;; when only one candidate is left
;; b. TAB (ac-expand) behave as completion (ac-complete)
;; after you select candidate
;; c. Disapear automatically when you
;; complete a candidate.
;;
;; DWIM mode is enabled by default.
;; You can enable this feature by
;; setting `ac-dwim' to t.
;;
(setq ac-dwim t)
;;------------------------------------------------------------------------------
;; quit a frame the same way no matter what kind of frame you are on"
;;------------------------------------------------------------------------------
;;This method, when bound to C-x C-c, allows you to close an emacs frame the
;;same way, whether it's the sole window you have open, or whether it's
;;a "child" frame of a "parent" frame. If you're like me, and use emacs in
;;a windowing environment, you probably have lots of frames open at any given
;;time. Well, it's a pain to remember to do Ctrl-x 5 0 to dispose of a child
;;frame, and to remember to do C-x C-x to close the main frame (and if you're
;;not careful, doing so will take all the child frames away with it). This
;;is my solution to that: an intelligent close-frame operation that works in
;;all cases (even in an emacs -nw session).
;;(global-set-key "\C-x\C-c" 'ic) ;forward reference
(defun ic ()
"quit a frame the same way no matter what kind of frame you are on"
(interactive)
(if (eq (car (visible-frame-list)) (selected-frame))
;;for parent/master frame...
(if (> (length (visible-frame-list)) 1)
;;close a parent with children present
(delete-frame (selected-frame))
;;close a parent with no children present
(save-buffers-kill-emacs))
;;close a child frame
(delete-frame (selected-frame))))
;;------------------------------------------------------------------------------
;; hithlight-80+:
;;------------------------------------------------------------------------------
;;(add-to-list 'load-path "~/.emacs.d/")
;;(global-highlight-80+-mode t)
(require 'highlight-80+)
(add-hook 'f90-mode-hook 'highlight-80+-mode)
;;------------------------------------------------------------------------------
;; 自动补全括号
;; 输入左边的括号,就会自动补全右边的部分.包括(), "", [] , {} , 等等。
;;------------------------------------------------------------------------------
(defun auto-pair ()
(interactive)
(make-local-variable 'skeleton-pair-alist)
(setq skeleton-pair-alist '(
(\"_"\"")
(\'_"'")
(\(")")
(\[_"]")
(\{_"}")
;(?\{?_"}")
))
(setq skeleton-pair t)
(local-set-key (kbd "\"") 'skeleton-pair-insert-maybe)
(local-set-key (kbd "(") 'skeleton-pair-insert-maybe)
(local-set-key (kbd "{") 'skeleton-pair-insert-maybe)
(local-set-key (kbd "'") 'skeleton-pair-insert-maybe)
(local-set-key (kbd "[") 'skeleton-pair-insert-maybe))
(add-hook 'f90-mode-hook 'auto-pair)
;;------------------------------------------------------------------------------
;; redo/undo
;;------------------------------------------------------------------------------
(require 'redo)
(global-set-key (kbd "C-/") 'undo)
(global-set-key (kbd "M-/") 'redo)

;;------------------------------------------------------------------------------
;; flyspell.el
;;
;; flyspell is an Emacs package that highlights misspelld words as you type;
;; Remark:
;; `flyspell-mode' uses `ispell-mode'. Thus all Ispell options are
;; valid. For instance, a personal dictionary can be used by
;; invoking `ispell-change-dictionary'.
;;
;; ispell-program-name = "aspell"
;; ispell-aspell-dict-dir = "/usr/lib/aspell"
;;------------------------------------------------------------------------------
;; enable flyspell-mode (minor mode) in latex-mode (major mode)
(add-hook 'latex-mode-hook 'flyspell-mode)
;; enable flyspell-prog-mode (minor mode) in f90-mode (major mode)
;;(add-hook 'f90-mode-hook 'flyspell-prog-mode)
(setq ispell-local-dictionary "american")
;;(setq ispell-local-dictionary "french")

jeudi 6 mai 2010

search in linux

1. find
find是最常见和最强大的查找命令,你可以用它找到任何你想找的文件。
find的使用格式如下:
  $ find <指定目录> <指定条件> <指定动作>
  - <指定目录>: 所要搜索的目录及其所有子目录。默认为当前目录。
  - <指定条件>: 所要搜索的文件的特征。
  - <指定动作>: 对搜索结果进行特定的处理。
如果什么参数也不加,find默认搜索当前目录及其子目录,并且不过滤任何结果(也就是返回所有文件),将它们全都显示在屏幕上。
find的使用实例:
  $ find . -name 'my*'
搜索当前目录(含子目录,以下同)中,所有文件名以my开头的文件。
  $ find . -name 'my*' -ls
搜索当前目录中,所有文件名以my开头的文件,并显示它们的详细信息。
  $ find . -type f -mmin -10
搜索当前目录中,所有过去10分钟中更新过的普通文件。如果不加-type f参数,则搜索普通文件+特殊文件+目录。

2. locate
locate命令其实是“find -name”的另一种写法,但是要比后者快得多,原因在于它不搜索具体目录,而是搜索一个数据库(/var/lib/locatedb),这个数据库中含有本地所有文件信息。Linux系统自动创建这个数据库,并且每天自动更新一次,所以使用locate命令查不到最新变动过的文件。为了避免这种情况,可以在使用locate之前,先使用updatedb命令,手动更新数据库。
locate命令的使用实例:
  $ locate /etc/sh
搜索etc目录下所有以sh开头的文件。
  $ locate ~/m
搜索用户主目录下,所有以m开头的文件。
  $ locate -i ~/m
搜索用户主目录下,所有以m开头的文件,并且忽略大小写。

3. whereis
whereis命令只能用于程序名的搜索,而且只搜索二进制文件(参数-b)、man说明文件(参数-m)和源代码文件(参数-s)。如果省略参数,则返回所有信息。
whereis命令的使用实例:
  $ whereis grep

4. which
which命令的作用是,在PATH变量指定的路径中,搜索某个系统命令的位置,并且返回第一个搜索结果。也就是说,使用which命令,就可以看到某个系统命令是否存在,以及执行的到底是哪一个位置的命令。
which命令的使用实例:
  $ which grep

5. type
type命令其实不能算查找命令,它是用来区分某个命令到底是由shell自带的,还是由shell外部的独立二进制文件提供的。如果一个命令是外部命令,那么使用-p参数,会显示该命令的路径,相当于which命令。
type命令的使用实例:
  $ type cd
系统会提示,cd是shell的自带命令(build-in)。
  $ type grep
系统会提示,grep是一个外部命令,并显示该命令的路径。
  $ type -p grep
加上-p参数后,就相当于which命令。

mercredi 5 mai 2010

emacs shell history

41.5.1 Shell History Ring

M-p
C-
Fetch the next earlier old shell command.


M-n
C-
Fetch the next later old shell command.


M-r regexp
M-s regexp
Search backwards or forwards for old shell commands that match regexp.
C-c C-x
Fetch the next subsequent command from the history.
C-c .
Fetch one argument from an old shell command.
C-c C-l
Display the buffer's history of shell commands in another window (comint-dynamic-list-input-ring).
Shell buffers provide a history of previously entered shell commands. To reuse shell commands from the history, use the editing commands M-p, M-n, M-r and M-s. These work just like the minibuffer history commands except that they operate on the text at the end of the shell buffer, where you would normally insert text to send to the shell.

M-p fetches an earlier shell command to the end of the shell buffer. Successive use of M-p fetches successively earlier shell commands, each replacing any text that was already present as potential shell input. M-n does likewise except that it finds successively more recent shell commands from the buffer. C- works like M-p, and C- like M-n.

The history search commands M-r and M-s read a regular expression and search through the history for a matching command. Aside from the choice of which command to fetch, they work just like M-p and M-n. If you enter an empty regexp, these commands reuse the same regexp used last time.

When you find the previous input you want, you can resubmit it by typing , or you can edit it first and then resubmit it if you wish. Any partial input you were composing before navigating the history list is restored when you go to the beginning or end of the history ring.

Often it is useful to reexecute several successive shell commands that were previously executed in sequence. To do this, first find and reexecute the first command of the sequence. Then type C-c C-x; that will fetch the following command—the one that follows the command you just repeated. Then type to reexecute this command. You can reexecute several successive commands by typing C-c C-x over and over.

The command C-c . (comint-input-previous-argument) copies an individual argument from a previous command, like ESC . in Bash. The simplest use copies the last argument from the previous shell command. With a prefix argument n, it copies the nth argument instead. Repeating C-c . copies from an earlier shell command instead, always using the same value of n (don't give a prefix argument when you repeat the C-c . command).

These commands get the text of previous shell commands from a special history list, not from the shell buffer itself. Thus, editing the shell buffer, or even killing large parts of it, does not affect the history that these commands access.

Some shells store their command histories in files so that you can refer to commands from previous shell sessions. Emacs reads the command history file for your chosen shell, to initialize its own command history. The file name is ~/.bash_history for bash, ~/.sh_history for ksh, and ~/.history for other shells.

lundi 3 mai 2010

emacs 自动补全括号

;;-----------------------------------------------------------------------
;;自动补全括号
;;输入左边的括号,就会自动补全右边的部分.包括(), "", [] , {} , 等等。
(defun mode-auto-pair ()
(interactive)
(make-local-variable 'skeleton-pair-alist)
(setq skeleton-pair-alist '(
(?\" ? _ " \"")
(?\' ? _ " '")
(?\( ? _ " )")
(?\[ ? _ " ]")
(?\{ ? _ " } ")
))
(setq skeleton-pair t)
(local-set-key (kbd "\"") 'skeleton-pair-insert-maybe)
(local-set-key (kbd "(") 'skeleton-pair-insert-maybe)
(local-set-key (kbd "{") 'skeleton-pair-insert-maybe)
(local-set-key (kbd "'") 'skeleton-pair-insert-maybe)
(local-set-key (kbd "[") 'skeleton-pair-insert-maybe))
(add-hook 'f90-mode-hook 'mode-auto-pair)

好网站

http://blog.chinaunix.net/u3/99841/showart_1981496.html
http://vvoody.org/pub/howto/emacs/sams24emacs.html
http://fhf25.blog.sohu.com/74454393.html

http://www.dotemacs.de/

http://www.emacs.uniyar.ac.ru/doc/em24h/index.htm

http://www.emacs.uniyar.ac.ru/

highlight-80+.el

;;; highlight-80+.el --- highlight characters beyond column 80
;;
;; Copyright (C) 2008 Nikolaj Schumacher
;;
;; Author: Nikolaj Schumacher
;; Version: 1.0
;; Keywords: faces
;; URL: http://nschum.de/src/emacs/highlight-tabs/
;; Compatibility: GNU Emacs 22.x
;;
;; This file is NOT part of GNU Emacs.
;;
;; 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 2
;; of the License, 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.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see .
;;
;;; Commentary:
;;
;; This mode highlights all characters that cross the 80 character line limit.
;;
;;; Change Log:
;;
;; 2008-08-11 (1.0)
;; Initial release.
;;
;;; Code:

;;Add the following to your .emacs:
;; (add-to-list 'load-path "~/.emacs.d")
;; (require 'highlight-80+)
;;(add-hook 'f90-mode-hook 'highlight-80+-mode)

(defgroup highlight-80+ nil
"Highlight characters beyond column 80."
:group 'faces)

(defcustom highlight-80+-columns 132 ;;132 is the number for .f90
"*Number of columns to allow in lines."
:group 'highlight-80+
:type 'integer)

(defface highlight-80+-line
nil
"*Face for showing lines with over `highlight-80+-columns'."
:group 'highlight-80+-line)

(defface highlight-80+
'((((background dark)) (:background "blue"))
(((background light)) (:background "dark gray")))
"*Face for showing characters beyond column `highlight-80+-columns'."
:group 'highlight-80+-line)

(defface highlight-80+-first
nil
"*Face for showing the first character beyond `highlight-80+-columns'."
:group 'highlight-80+-line)

(defconst highlight-80+-keywords
`((highlight-80+-matcher (0 'highlight-80+-line prepend)
(1 'highlight-80+ prepend)
(2 'highlight-80+-first prepend))))

(defsubst highlight-80+-format ()
(if (<>
"^\\(\\)\\([^\n]\\)\\{80,\\}$"
(concat (format "^\\(?:[^\t\n]\\{%d\\}\\|[^\t\n]\\{,%d\\}\t\\)\\{%d\\}"
tab-width (- tab-width 1)
(/ highlight-80+-columns tab-width))
(let ((remainder (mod highlight-80+-columns tab-width)))
(when remainder
(format "\\(?:[^\t\n]\\{%d\\}\\|\t\\)" remainder)))
"\\(\\(.\\).*\\)$")))

(defvar highlight-80+-last-width 0)
(make-variable-buffer-local 'highlight-80+-last-width)

(defvar highlight-80+-last-keywords "")
(make-variable-buffer-local 'highlight-80+-last-keywords)

(defun highlight-80+-matcher (limit)
;; Update search when `tab-width' has changed.
(unless (equal highlight-80+-last-width tab-width)
(setq highlight-80+-last-keywords (highlight-80+-format)
highlight-80+-last-width tab-width)
;; The rest of the buffer can't be right, either.
(let ((font-lock-keywords))
(font-lock-fontify-buffer)))
;; re-search-forward is C and much faster checking columns ourselves
(re-search-forward highlight-80+-last-keywords nil t))

;;;###autoload
(define-minor-mode highlight-80+-mode
"Highlight the portions of lines longer than 80 characters."
nil " 80+" nil
(if highlight-80+-mode
(font-lock-add-keywords nil highlight-80+-keywords t)
(font-lock-remove-keywords nil highlight-80+-keywords)
(kill-local-variable 'highlight-80+-last-keywords)
(kill-local-variable 'highlight-80+-last-width))
(font-lock-fontify-buffer))

(provide 'highlight-80+)
;;; highlight-80+.el ends here

emacs zz

November 30
Emacs FAQ
* General

1. 怎样才能语法加亮
2. 在Windows版的Emacs下怎样使用ispell?
3. Windows版的Emacs为什么不能显示图片?
4. 设置打开文件的缺省路径
5. `.emacs' 在哪里?
6. 下载的el文件怎么用?
7. 怎么进行矩形区域操作?(类似UltraEdit的列模式) 怎么在每一行前插入相同文字?
8. 总有个带小尾巴~的文件出现(自动备份文件),怎么办?
9. 我想把一个命令绑定到某个按键组合上,怎么表示组合键?
10. 怎么转换文件格式?(DOS <--> UNIX)
11. 查找和替换的时候怎么输入回车之类的特殊字符?
12. M-x shell进入shell-mode出现乱码?怎么修改颜色和字体?
13. windows下插入、浏览图片时emacs崩溃
14. 如何跳到某一行?
15. 如何插入当前时间?
16. 修改 .emacs 后即时生效(不重启)?

* Chinese Related

1. Emacs与其他程序间为什么不能拷贝、粘贴
2. Emacs中新开buffer不使用默认字体怎么办
3. XEmacs怎样保存中文
4. 怎样使Emacs支持GBK

* TeX

1. Windows下不能使用LaTeX-preview
2. Emacs能象vimsuite那样加载类似CJK的模板么?

* Programming

1. 怎样把C/C++文件重新排版
2. 语法加亮
3. c/c++, java 自动补全功能?

* Gnus, Mail, Web

1. mew怎样使用SMTP验证?
2. 怎样使mew在pop取信时将信件保留在服务器上?
3. gnus怎样使用通讯录?

* Resources

1. 推荐Emacs入门书籍
2. 推荐Emacs Lisp入门书籍
3. 下载最新版本的GNU Emacs
4. ftp. tsinghua. edu. cn的Emacs专区
5. Emacs资源哪里最多?
6. 一个收集大量Emacs配置文件的网站

推荐下载FTP: ftp://ftp.tsinghua.edu.cn/Software/Editor/Emacs/
精华区下载 : ftp://ftp.smth.org/smth/announce

------------------------------------------------------------------------------
-

In details:

* General
=========

1.怎样才能语法加亮
将以下写到.emacs文件:(global-font-lock-mode t)

2.在Windows版的Emacs下怎样使用ispell?
Win32有一个native的ispell v4,但很不好用,建议装一个cygwin的ispell-3.2.06

3.Windows版的Emacs为什么不能显示图片?
使用cvs版的ntemacs,在.emacs中加入:(auto-image-file-mode t)

4.设置打开文件的缺省路径
(setq default-directory "~")

5.`.emacs' 在哪里?
Unix/Linux:

~/.emacs 如果没有,自己创建一个。`touch .emacs'.

Windows:

在根目录下创建一个名为".emacs"的文件
如果创建不了的话也可以用"_emacs"作为文件名
根目录由windows的环境变量HOME指定,如果没有设定HOME环境变量,一般为C:\

6.下载的el文件怎么用?
把文件放到load-path中去,然后按照文件头上的注释说明做。
~/site-lisp一般默认在load-path中
增加load-path例:(add-to-list 'load-path "/path/to/yours")

7.怎么进行矩形区域操作?(类似UltraEdit的列模式) 怎么在每一行前插入相同文字?
x-5-8

8.总有个带小尾巴~的文件出现(自动备份文件),怎么办?
小尾巴文件是备份,可以干掉它或者按文件名分类放到指定目录中去。
详细见x-5-2-4

9.我想把一个命令绑定到某个按键组合上,怎么表示组合键?
x-5-2-3

10.怎么转换文件格式?(DOS <--> UNIX)
C-x f (函数 set-buffer-file-coding-system)

11.查找和替换的时候怎么输入回车之类的特殊字符?
C-q之后输入
^M是C-q C-m,回车是C-q C-j,TAB是C-q TAB

12.M-x shell进入shell-mode出现乱码?怎么修改颜色和字体?
在.emacs中加入:(setq ansi-color-for-comint-mode t)
更多选项请:M-x customize-group ansi-colors

13.windows下插入、浏览图片时emacs崩溃
windows版本的emacs的图片支持dll是用mingw编译的,因此如果你的emacs是用VC编译
的,则可能出现意想不到的问题。建议选择用mingw编译的emacs(http://nqmacs.sf.net

14.如何跳到某一行 ?
`M-x goto-line', 推荐绑定在 `M-g' 键上.

15.如何插入当前时间?
一个例子:

(defun my-insert-date ()
(interactive)
(insert (format-time-string "%Y/%m/%d %H:%M:%S" (current-time))))

(global-set-key (kbd "C-c m d") 'my-insert-date)

16 修改 .emacs 后即时生效(不重启) ?
有几种方法:
1) M-x eval-last-sexp(or C-x C-e)
2) M-x eval-region
3) M-x eval-buffer


* Chinese Related
=================

1.Emacs与其他程序间为什么不能拷贝、粘贴
在~/.emacs加入这句话“(set-selection-coding-system 'cn-gb-2312)”

2.Emacs中新开buffer不使用默认字体怎么办
(add-to-list 'default-frame-alist '(font . "-*-SimSun-medium-r-normal-*-
12-*"))

3.XEmacs怎样保存中文
(prefer-coding-system 'gb2312)

4.怎样使Emacs支持GBK
去http://mule-gbk.sourceforge.net下载那个支持文件,按照里面的README
进行安装。
或者访问本版精华区x-5-3-3,有README贴文和elisp包附件。

* TeX
=====

1.Windows下不能使用LaTeX-preview
使用CVS的GNU Emacs或XEmacs就可以了

2.Emacs能象vimsuite那样加载类似CJK的模板么?
可以,使用template扩展可以加载任何格式的模板

* Programming
=============

1.怎样把C/C++文件重新排版
选择文本块,ESC C-\,M-X c-set-style,可以设置不同的缩进风格

2.语法加亮
(global-font-lock-mode t)

3. c/c++, java 自动补全功能?
c/c++ - ecb
java - jde

Both kind of *SLOW*, though.

* Gnus, Mail, Web
=================

1.mew怎样使用SMTP验证?
(setq mew-smtp-auth-list (quote ("CRAM-MD5" "LOGIN" "PLAIN")))

2.怎样使mew在pop取信时将信件保留在服务器上?
(setq mew-pop-delete nil)

3.gnus怎样使用通讯录?
可以用 bbdb

*Emacs Fill 详解
Emacs 具有非常智能的文本编辑能力。它可以自动对文字断行,并且在断开的行首都加入一些 prefix(前缀)。

你编辑 C 程序多行注释的时候,你想要编辑器能够自动缩进到合适的位置并且插入一个 "*",就像这样?

/* seed the random number generator
* first try the random file /dev/random
* if there isn't such a file in the system
* use current time to seed the RNG.
*/
在你写新闻组的文章的时候,你又想让编辑器使你的文档出现这样漂亮的缩进:

1. I seed the random number generator first try the random file
/dev/random if there isn't such a file in the system use current
time to seed the RNG.

2. I need more powerful randomized binary search tree algorithm to
store my wavefront elements.
这些 * 和 行首留出的空白就叫做 prefix。每当使用 fill-paragraph 等操作或者启动了 auto-fill-mode 的时候,文字在断行时,Emacs 可能会在断开的每行前面加入 prefix(前缀)。这大大方便了编辑类似程序注释这一类文字。

设置 fill-column
fill-column就是说到多少列的时候断行。你可以使用

C-u 70 C-x f
这样的命令把 fill-column 设置为 70. 也可以把光标移动到你想要断行的位置,然后按
C-u C-x f
断开的行可能会被自动加上一个前缀(prefix)。设置prefix的方式主要有两种,手动设置和 adaptive prefix 自动设置。

手动设置 prefix
如果把光标放在段落首后面一个位置,使用

C-x . (set-fill-prefix)
就可以把段落头到光标处的那段字符作为 prefix.
Adaptive Filling
但是没有手动设置 prefix 的时候,Emacs 也可以自动识别段落首的一些字符作为 prefix。这就叫做 Adaptive Filling。

提取候选前缀
Emacs 使用变量 adaptive-fill-regexp 来提取前缀。这个变量是一个正则表达式。它会把fill区域开头的能够匹配的部分作为候选的前缀。很多 major mode 会自动帮你设置好这个变量,所以你通常不用操心。

但是某些时候,你可能希望能够自己操纵这一切。我们下面就来看一个具体的例子。假设如果你要达到这种效果,在同一个文本文件里:

有一些段落每行由3个 * 开头,这可以被作为一小节的标题以及简短的说明。比如:
*** Section "Files". The location
of the RGB database. Note, this
is the name of the file minus
the extension (like ".txt" or
".db").
有一些段落每行由一个 * 号开头,这叫做“强调”。像这样:
* There is normally no need to
* change the default. Multiple
* FontPath entries are allowed
* (they are concatenated together)
* By default, Red Hat 6.0 and later
* now use a font server independent
* of the X server to render fonts.
有一些段落由数字编号 1. 2. 3. 开头,以后的每一行要求缩进到标号之后。所有的数字后面的点号要对齐。
1. I seed the random number generator first try the random file
/dev/random if there isn't such a file in the system use current
time to seed the RNG.

2. I need more powerful randomized binary search tree algorithm to
store my wavefront elements.
这些 "*** ", "* ", "1. ", "2. ", " " 就叫做前缀。为了识别这些前缀,我们把 adaptive-fill-regexp 设置为:

(setq adaptive-fill-regexp "[ \t]+\\|[ \t]*\\([0-9]+\\.\\|\\*+\\)[ \t]*")
这表示前缀可以全是空白字符。或者开头可以有一些空白,接着数字加点或者一个以上的 *,接着一些空白。那么 Emacs 发现开头有这样的字样时,就会把这个字符串作为一个“候选前缀”。

候选前缀的选择
我们已经轻松提取了可能作为前缀的部分,但是一个候选前缀是否被使用,还有很多因素。Emacs 的策略是非常聪明的。我们下面来看看 Emacs 是怎样为用户着想的。

多行文字的前缀 — 使用第二行的前缀
首先,我们经常有这样一种想法:如果我两行开头都有符合候选前缀条件的符号,编辑器应该把第二行的那个候选作为前缀。如果我们输入一些文字:

1. I seed the random number generator
first try the random file
/dev/random if there isn't such a file in the system use current time to seed the RNG.
我们第一行输入了一个前缀 "1. ",第二行我们故意退了几格,使得 "1. " 这种数字标号突出在段落之外。但是其它的文字我们可以先不用管。那么第一行找到的候选前缀就是 "1. "(1,一个点,一个空格),第二行的候选前缀是" "(3个空格)。
写完一段时,我们按 M-q,这段话就自动采用了第二行的前缀(3个空格)作为 prefix。变成这个样子:

1. I seed the random number generator first try the random file
/dev/random if there isn't such a file in the system use current
time to seed the RNG.
如果我们后来不满意。想把第二行开始的那些行多缩进一些,而且把 fill-column 减小一些。我们可以设置 fill-column,然后在第二行开头再加一些空格,按 M-q。就成了这样:
1. I seed the random number generator
first try the random file
/dev/random if there isn't such
a file in the system use
current time to seed the RNG.
想一下你如果不用 Emacs,如何把上面那段文字变成现在这样!
单行文字的前缀选择
那么如果我们只输入了一行字就要求把这行的前缀作为所有断开的行的前缀呢?比如,我们输入一行,开头以 * 开始。我们希望它在fill的时候断开的行都以 * 开头。

这是通过设置 adaptive-fill-first-line-regexp 这个变量实现的。这个变量是一个正则表达式。如果它能够匹配我们用 adaptive-fill-regexp 提取出来的前缀,那么这个前缀就被采用。

(setq adaptive-fill-first-line-regexp "^\\* *$")
注意我们没有使用简单的 "\\* *",而是使用了行首和行尾的匹配符号,因为我们只希望 "* " 这样的符号作为单行重复前缀,出现在每行的开头,而不希望 "***" 成为每行的开头。 adaptive-fill-regexp 提取出来的候选前缀被作为了 adaptive-fill-first-line-regexp 的输入行,它有行首和行尾。

我们这是在告诉 Emacs,单行文字如果由一个 * 开头,那么断行后每一行都以 * 作为 prefix。

如果我们输入一行(麻烦你拖动一下:P) :

* There is normally no need to change the default. Multiple FontPath entries are allowed (they are concatenated together) By default, Red Hat 6.0 and later now use a font server independent of the X server to render fonts.
按 M-q,它就变成了:
* There is normally no need to change the default. Multiple FontPath
* entries are allowed (they are concatenated together) By default, Red
* Hat 6.0 and later now use a font server independent of the X server
* to render fonts.
如果adaptive-fill-first-line-regexp 不能匹配从单行取出的前缀,Emacs 会把这个前缀转成同样长度的空格作为前缀,这正是我们想要的结果。比如我们输入:

*** Section "Files". The location of the RGB database. Note, this is the name of the file minus the extension (like ".txt" or ".db").
由于 "^\\* *$" 不能匹配提取出来的候选前缀 "*** ",所以 Emacs 把跟它同样长度的4个空格作为了前缀。这样 fill 之后变成了:
*** Section "Files". The location of the RGB database. Note, this is
the name of the file minus the extension (like ".txt" or ".db").
这正是我们希望的样子。
*启动 Outline
M-x outline-minor-mode 就可以启动 Outline。还有一个 outline-mode 是一个 major mode,一般都不用它。
全局隐藏操作
光标在任何位置,只要执行这些操作,文档的显示就会变化成需要的样子。
hide-sublevels(C-o C-q)
这个操作如果不带参数,隐藏所有文档子结构,只剩最上层。
M-4 hide-sublevels(M-4 C-o C-q)
这是参数为4的操作,显示至文档第4层子结构。
hide-body(C-o C-t)
文档的所有 Entry 都被隐藏。只显示主干。
对一个子树(Chapter 1)的隐藏操作
hide-subtree(C-o C-d)
所有文档部分展开时,光标移动到 Chapter 1,执行 hide-subtree。整个 Chapter 1 的子树被折叠起来。
hide-other(C-o C-o)
所有文档部分展开时,光标移动到 Chapter 1,执行 hide-other。除了 Chapter 1,其它子树全部被折叠起来。这个操作正好与 hide-subtree 互补。
hide-leaves(C-o C-l)
所有文档部分展开时,光标移动到 Chapter 1,执行 hide-leaves。所有 Chapter 1 子树下的所有级别的 entry 被隐藏。也就是说,Chapter 1 下,只显示 branch.
hide-entry(C-o C-c)
所有文档部分展开时,光标移动到 Chapter 1,执行 hide-entry。Chapter 1 的 Entry 被隐藏,但是所有子树都不动。
全局显示操作
show-all(C-o C-a)
显示所有文档。结果就是原文档。
对一个子树的显示操作
为了演示,我们从全部隐藏的情况开始:
show-children(C-o C-i)
show-children 只显示直接的下一代子树,而不显示间接的下一代。这里, \begin{document} 的直接的下一代就是 \chapter{...}。
show-entry(C-o C-e)
把光标移动到 Chapter 1,执行 show-entry。Chapter 1 的 Entry 被显示,但是所有子结构还是保持隐藏。
show-branches(C-o C-k)
把光标移动到 Chapter 1,执行 show-branches。Chapter 1 这棵子树之下的各级“树干”被显示,但是各级 entry 还是保持隐藏。Chapter 1 自己的 entry,由于我们上一步已经显示,所以保持不变。
show-subtree(C-o C-s)
把光标移动到 Chapter 1,执行 show-subtree。Chapter 1 及其所有子结构全部被扩展。
Outline mode 下的移动操作
在 outline 模式下,有几种特殊方便的移动方式。
C-o C-n (outline-next-visible-heading) 移动到下一个可见标题。
C-o C-p (outline-previous-visible-heading) 移动到上一个可见标题。
C-o C-f (outline-forward-same-level) 移动到下一个同级可见标题。
C-o C-b (outline-backward-same-level) 移动到上一个同级可见标题。
C-o C-u (outline-up-heading) 到上一级标题。
* Resources
===========

1.推荐Emacs入门书籍
a.Sams Teach Yourself Emacs in 24 Hours
可以从http://learn.tsinghua.edu.cn/homepage/2001315450/emacs_doc.html
在线阅读。在ftp.tsinghua.edu.cn中可以下载全文、光盘中的内容以及官方网站
上的一些东西。不要被书名所迷惑,你不可能在24小时内学会的。
b.《学习GNU Emacs》
O'Reilly和机械工业出版社出版的,定价很高,¥68.00。清华的图书馆有藏书,
索书号: TP391.12_K073,借的人很多,需要提前预约。

2.推荐Emacs Lisp入门书籍
a.GNU Emacs Lisp编程入门
涵盖了入门需要的几乎所有知识,写给没用过Emacs,没学过lisp;但是用过编辑器
会写程序的人看的入门书。这本书最好用info看,一边看一边就可以试。在info里面
显示为Emacs Lisp Intro。
b.GNU Emacs Manual
速查手册,info里面显示为Elisp。

3.下载最新版本的GNU Emacs
可以使用cvs方式:
*nix下: cvs -z3 -d:ext:anoncvs@savannah.gnu.org:/cvsroot/emacs co emacs
windows下: 可以用cygnus下的cvs(推荐), 也可以装一个WinCVS
http://nqmacs.sourceforge.net 这里可以下载NTemacs的最新CVS版
4.ftp.tsinghua.edu.cn的Emacs专区
有三种访问方式
http://ftp.tsinghua.edu.cn/pub/Software/Emacs/
ftp://ftp.tsinghua.edu.cn/Software/Emacs/
rsync://ftp.tsinghua.edu.cn/pub/Software/Emacs/

5.Emacs资源哪里最多?
[Emacs Wiki] http://www.emacswiki.org
[Emacs Wiki Elisp List] 很全的elisp list
http://www.emacswiki.org/cgi-bin/wiki/WikifiedEmacsLispList

6.一个收集大量Emacs配置文件的网站
http://www.dotemacs.de/

emacs help (C-h)

函数名(FUNCTION) 快捷键(KEYS) 帮助文件(manual)
1. 函数名(FUNCTION)-> 快捷键(KEYS) + 帮助文件(manual)
C-h f FUNCTION %Display documentation for the given function.
2. 快捷键(KEYS) -> 函数名(FUNCTION)
C-h c KEYS %Display documentation for the given function.
3. 快捷键(KEYS) -> 函数名(FUNCTION)+ 帮助文件(manual)
C-h k KEYS %Display the full documentation for the key sequence.
C-h K KEYS %Show the on-line manual's section for the command bound to KEYS.

------------------
C-h ?
------------------
You have typed C-h, the help character. Type a Help option:
(Use SPC or DEL to scroll through this text. Type q to exit the Help command.)

a PATTERN Show commands whose name matches the PATTERN (a list of words
or a regexp). See also the `apropos' command.
b Display all key bindings.
c KEYS Display the command name run by the given key sequence.
C CODING Describe the given coding system, or RET for current ones.
d PATTERN Show a list of functions, variables, and other items whose
documentation matches the PATTERN (a list of words or a regexp).
e Go to the *Messages* buffer which logs echo-area messages.
f FUNCTION Display documentation for the given function.
F COMMAND Show the on-line manual's section that describes the command.
g Display information about the GNU project.
h Display the HELLO file which illustrates various scripts.
i Start the Info documentation reader: read on-line manuals.
I METHOD Describe a specific input method, or RET for current.
k KEYS Display the full documentation for the key sequence.
K KEYS Show the on-line manual's section for the command bound to KEYS.
l Show last 300 input keystrokes (lossage).
L LANG-ENV Describes a specific language environment, or RET for current.
m Display documentation of current minor modes and current major mode,
including their special commands.
n Display news of recent Emacs changes.
p TOPIC Find packages matching a given topic keyword.
r Display the Emacs manual in Info mode.
s Display contents of current syntax table, plus explanations.
S SYMBOL Show the section for the given symbol in the on-line manual
for the programming language used in this buffer.
t Start the Emacs learn-by-doing tutorial.
v VARIABLE Display the given variable's documentation and value.
w COMMAND Display which keystrokes invoke the given command (where-is).
. Display any available local help at point in the echo area.

C-a Information about Emacs.
C-c Emacs copying permission (GNU General Public License).
C-d Instructions for debugging GNU Emacs.
C-e External packages and information about Emacs.
C-f Emacs FAQ.
C-m How to order printed Emacs manuals.
C-n News of recent Emacs changes.
C-o Emacs ordering and distribution information.
C-p Info about known Emacs problems.
C-t Emacs TODO list.
C-w Information on absence of warranty for GNU Emacs.


http://lifegoo.pluskid.org/wiki/EmacsTip.html

dimanche 2 mai 2010

Search and Replace

search for works没有搞懂

以在下面一段文字中搜索第五行的ab为例:
------
1 a
2 ab
3 abc
4 abcd
5 ab

M-<
%emacs搜索范围从光标位置处开始知道buffer结束。
%为了让搜索覆盖全局,需要使用 M-< 把光标调整到 buffer开始处。
C-s (C-r)
%向前搜索 (C-r向后搜索)
I-search:\
%如果刚开始的时候只输入想搜索单词的前面部分,光标会停留到第一个符合条件的位置,即 1 a C-s (C-r)
%光标移动到下一个符合条件的位置 2 ab
C-w
%which will append the rest of the word to the search string
C-s
%go to 3 abc with this modified search string
C-s
%go to 4 abcd with this modified search strin
C-s
%go to 5 ab with this modified search strin Enter %press the Enter key to exit the incremental search.

Exiting a Search
C-g C-g

Using an Old Search String
C-s (C-r)
M-p (M-n)
%To do this, press either C-s or C-r to search through your search history, and then press M-p to search backward in the history of search strings. If you get too far back, you can press M-n to search forward once again. When you find the string that you want to use, you can modify it if it is not the exact string you want to search for. When you are happy about the string, you can start the search by pressing the Enter key.

Copy the text have marked
C-s (C-r)
M-y
%If you have marked some text and you want to append this to your search string, you can press M-y. This also means that if you have some marked text that you want to search for, you simply press C-s M-y.

Listing Lines that Match a Pattern
C-2 M-x occur RET
ab RET
%If you give this function a numerical prefix (that is, by pressing C-3 before the function) then that many lines of context are shown.
%The screen is split in two--in the upper part your original buffer is shown, and in the lower part, the special occur buffer is shown. If you press Enter or the middle mouse button over one of these matches, Emacs will proceed to this location in your original buffer.

Search and Replace
M-%
Options when Replacing

For each occurrence of the search string, Emacs offers to do one of several actions. Previously, you saw two of them: Replace this occurrence and replace the rest of the occurrences.

The following choices exist:

Space or y--This replaces the current match and continues to the next one.

Delete or n--This skips the current match and continues to the next one. In other words, it doesn't replace the current match.

Enter or q--This terminates the query-replace operation and, therefore, doesn't replace any more matches. The matches already replaced will remain replaced.

!--This replaces the remaining occurrences in the rest of the buffer without asking for permission.

, (the comma character)--This replaces the current match but doesn't continue to the next one. That way, you can get the match replaced and see whether Emacs does it correctly. To continue on to the next match, press y. If you dislike the replacement, you can either abort the query-replace and undo, or use recursive editing to fix it. (Recursive editing is described in the following section)

C-g--This aborts the search-and-replace operation.

^ (the caret character)--This moves the cursor back to the previous replacement. (You can go back as many steps as you want.) To continue your replacement press y. If you want to correct the previous replacement, (you must use recursive editing).

C-l--This centers the line with the match in the middle of the window. This enables you to see the text around the match.

C-r--This enters recursive editing, which is described in the following section.

Recursive Editing

When you use query-replace in your buffer, you might find that there is an error of some kind in the surrounding text of the word being replaced. You can do several things about that.

You can try to remember the location and go back to it, when you are finished with your search-and-replace. Unfortunately, this method works only if you have a superb brain like Einstein; otherwise, you will forget the location when you are finished with your search-and-replace. An alternative is to write the location down. This is better than the first solution, but if your document is large, you might end up with many such notes on your paper, and when you get back to the location, you will find that you have forgotten what the problem was.

The ultimate solution is to fix the problem immediately and continue your search-and-replace afterward.

Totally aborting your search-and-replace operation is not a good idea, because this means that you might have to tell Emacs to skip several replacements when you start search-and-replace again. What you really need is to tell Emacs to pause the search-and-replace operation, fix the problem, and ask Emacs to continue after you finish.

Fortunately, Emacs offers exactly that capability. It is called recursive editing .

To enter recursive editing from your search-and-replace operation, press C-r. When you finish that, you can work with Emacs as you normally do. (You can, in fact, start another search-and-replace operation while the first is pausing; watch out if you do, because things might get messy).

When you enter recursive editing, the modeline includes a pair of square brackets around the parentheses to indicate that you are in recursive editing.

To exit recursive editing and continue with your search-and-replace press C-M-c.

samedi 1 mai 2010

Emacs 搜索

替换操作:全局替换命令与查询替换命令 (不能匹配单个单词)
  在Emacs编辑器中,可以使用全局替换命令或查询替换命令操作来实现文本的替换。查询替换操作允许执行单个的替换,当执行查询替换操作时,如果编辑器查找到与输入匹配的字符串,编辑器将询问是替换该字符串还是不执行替换操作而直接进行下一次与输入匹配的查找,或者退出当前的查询替换操作。因此,执行替换时,查询替换比全局替换具有更多的控制权。进行正则表达式搜索时,这两个操作都有与之对应的特殊命令。
  1. 全局替换:Replace-string命令
  可以直接在编辑器的小缓冲区中使用replace-string命令来执行全局替换操作,且在键入replace-string命令后,不必键入任何键。其操作过程如下:首先键入Esc x命令进入编辑器的小缓冲区,然后键入replace-string命令,编辑器提示用户输入要查找的字符串及要替换的字符串。Replace- string命令不能实现正则表达式的替换,如果要使用正则表达式,必须使用replace-regexp命令。
  2. 查询替换命令
  Esc %命令用来执行查询替换操作。它首先搜索到与模式匹配的字符串,然后在必要时替换该字符串。要执行查询替换命令,首先键人Esc %命令,然后键入要被替换的模式,并回车,再键入要替换的字符串并回车。完成上述操作之后,将搜索到与被替换的模式匹配的第一个字符串,同时出现几个选项,每个选项都有与之对应的按键。例如,如果键入y,搜索到的字符串将被替换字符串所替换,同时,光标将位于已被替换掉的字符串上;如果键入n,将取消替换操作,同时,光标将位于搜索到的字符串上。其格式如下:
Esc %
  Query replace:<被替换字符串>
  Query replace <被替换字符串> with:<替换字符串>
  Query replacing <被替换字符串> with <替换字符串>:(? for help)
  查询替换命令的选项见下表:
  y或者Spacebar键 替换搜索到的字符串
  n或者Del键 取消替换搜索到的字符串
  ^ 回到前一个搜索到的字符串
  ! 替换所有没有替换的与模式匹配的字符串
  ESC键 退出本次查询搜索
  下面的命令序列将用yogurt字符串替换文本中的模式milk,然后继续下一次查找。用户可以按Esc键退出查询搜索操作。
  Esc %
   Query replace: milk
  Query replace milk with: yogurt
  Query replacing milk with yogurt:(? For help) y
  与其他查找命令一样,查询搜索命令不允许在输入的查找字符串中使用特殊字符。但如果想使用特殊字符,可以使用query-replace-regexp 命令,要运行该命令,必须首先键入Esc x命令进入编辑器的小缓冲区中。

比较有用lisp:
http://blog.csdn.net/pankun/archive/2007/04/25/1584873.aspx


m-x find-grep-dired


http://www.zoomquiet.org/share/doc/docs.huihoo.com/homepage/shredderyin/emacs24/emacs059.htm#c1

Fortran functions: num2str and str2num

program main
implicit none
character*10,external::num2str ! add in program main
integer,external::str2num !add in program main
integer::num
character*10::str

num=100
str="100"
print*,num2str(num)
print*,str2num(str)
end program main

!---function num2str and str2num----------------
function num2str(num)
implicit none
integer::num
character*10::num2str
!
write(num2str,"(I0)")num
!
return
end function num2str

function str2num(str)
implicit none
character*10::str
integer::str2num
!
read(str,*)str2num
!
return
end function str2num

emacs .emacs重新加载

修改完.emacs后, 可以使用M-x eval-buffer重新加载.emacs.

emacs -nw

emacs --help
--no-window-system, -nw do not communicate with X, ignoring $DISPLAY
也就是使用命令:emacs -nw ,就可以在terminal中打开emacs。

但是发现打开的frame无法使用快捷键C-x C-c关闭。借用网络上牛人的lisp,如下。也就是使用M-x ic关闭frame。


;;This method, when bound to C-x C-c, allows you to close an emacs frame the
;;same way, whether it's the sole window you have open, or whether it's
;;a "child" frame of a "parent" frame. If you're like me, and use emacs in
;;a windowing environment, you probably have lots of frames open at any given
;;time. Well, it's a pain to remember to do Ctrl-x 5 0 to dispose of a child
;;frame, and to remember to do C-x C-x to close the main frame (and if you're
;;not careful, doing so will take all the child frames away with it). This
;;is my solution to that: an intelligent close-frame operation that works in
;;all cases (even in an emacs -nw session).
;;(global-set-key "\C-x\C-c" 'ic) ;forward reference
(defun ic ()
"quit a frame the same way no matter what kind of frame you are on"
(interactive)
(if (eq (car (visible-frame-list)) (selected-frame))
;;for parent/master frame...
(if (> (length (visible-frame-list)) 1)
;;close a parent with children present
(delete-frame (selected-frame))
;;close a parent with no children present
(save-buffers-kill-emacs))
;;close a child frame
(delete-frame (selected-frame))))