my elisp subroutine
;; this two are useful
(defun next-user-buffer ()
"Switch to the next user buffer in cyclic order.\n
User buffers are those not starting with *."
(interactive)
(next-buffer)
(let ((i 0))
(while (and (string-match "^*" (buffer-name)) (< i 50))
(setq i (1+ i)) (next-buffer) )))
(defun previous-user-buffer ()
"Switch to the previous user buffer in cyclic order.\n
User buffers are those not starting with *."
(interactive)
(previous-buffer)
(let ((i 0))
(while (and (string-match "^*" (buffer-name)) (< i 50))
(setq i (1+ i)) (previous-buffer) )))
(global-set-key (kbd "C-<prior>") 'previous-user-buffer) ; Ctrl+PageDown
(global-set-key (kbd "C-<next>") 'next-user-buffer) ; Ctrl+PageUp
;;(defun insert-first-tag ()
;; "Insert ==== at cursor point."
;; (interactive)
;; (insert "====")
;; (backward-char 2))
;; (global-set-key (kbd "\C-cf") 'insert-first-tag)
(defun insert-second-tag ()
"Insert ======at cursor point."
(interactive)
(insert "======")
(backward-char 3))
(global-set-key (kbd "\C-cs") 'insert-second-tag)
;;(defun internal-link ()
;; "Insert a markup [[]] around a region."
;; (interactive)
;; (save-excursion
;; (goto-char (region-end)) (insert "]]")
;; (goto-char (region-beginning)) (insert "[[")
;; ))
;;(global-set-key (kbd "\C-ci") 'internal-link)
(setq show-paren-style 'expression) ; highlight entire expression
(setq w32-pass-lwindow-to-system nil
w32-pass-rwindow-to-system nil
w32-pass-apps-to-system nil
w32-lwindow-modifier 'super ; Left Windows key
w32-rwindow-modifier 'super ; Right Windows key
w32-apps-modifier 'hyper) ; Menu key
(global-set-key (kbd "\C-ct") (lambda () (interactive) (insert "~~~~") ))
;; 如何实现编译后,打开。
;;;;;;; 问题在哪?;;;;;;;;;;;;;;;;;;;;;;
;;(defun execuate()
;; (interactive)
;; (shell-command (concat (file-name-sans-extension
;; (buffer-name))
;; )))
;; 这一段 留作参考。;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;http://www.cppblog.com/3144046cjc/archive/2009/08/08/92583.html
;;(setq compile-command (concat "g++ -g " "\"" buffer-file-name "\""))
(global-set-key (kbd "s-i") 'smart-compile)
(defun smart-compile()
(interactive)
;; (let ((candidate-make-file-name '("makefile" "Makefile" "GNUmakefile"))
;; (command nil))
;; (if (not (null
;; (find t candidate-make-file-name :key
;; '(lambda (f) (file-readable-p f)))))
;; (setq command "make -k ")
;; 没有找到 Makefile ,查看当前 mode 是否是已知的可编译的模式
(let ((command nil))
(cond ((null (buffer-file-name (current-buffer)))
(message "Buffer not attached to a file, won't compile!"))
((eq major-mode 'c-mode)
(setq command
(concat "gcc.exe -Wall -o "
(file-name-sans-extension
(buffer-name)) ;;注意,这里的路径的斜杠和vista的习惯相反,你要注意修改
".exe"
(buffer-name)
" -g -lm ")))
((eq major-mode 'c++-mode)
(setq command
(concat "g++.exe -Wall -o " ;;还有这里的g++,也同gcc一样...
(file-name-sans-extension
(buffer-name))
".exe "
(buffer-name)
" -g -lm ")))
((eq major-mode 'python-mode)
(setq command
(concat "python " ;;还有这里的g++,也同gcc一样...
(buffer-name)
)))
((eq major-mode 'perl-mode)
(setq command
(concat "perl " ;;还有这里的g++,也同gcc一样...
(buffer-name)
)))
(t (message "Unknow mode, won't compile!")))
;; (if (not (null command))
;; (let ((command (read-from-minibuffer "Compile command: " command)))
(compile command)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; insert-date
(defun insert-date () ;
"Insert date at point." ;
(interactive) ;
(insert (format-time-string "%Y年%m月%e日 %l:%M %a %p"))) ;
(global-set-key (kbd "C-1") 'delete-other-windows) ;; Alt-1 关闭其它窗口
(global-set-key (kbd "C-2") 'split-window-vertically) ; Alt-2 垂直分割窗口
(global-set-key (kbd "C-3") 'split-window-horizontally); Alt-3 水平分割窗口
(global-set-key (kbd "C-4") 'delete-window) ;关闭窗口
(global-set-key (kbd "M-1") 'kill-buffer) ;关闭buffer
(global-set-key (kbd "C-Z") 'other-window) ;;哈哈,C-Z不再没作用了
;; it it not usefual now
;; M-w will copy the current line
(defun duplicate-line()
(interactive)
(move-beginning-of-line 1)
(kill-line)
(yank)
)
(global-set-key (kbd "C-d") 'duplicate-line)