window配置emacs编译c++程序

    技术2022-06-26  56

    先记下来,以免日后需要

     

    先是设置home

    Win+R  regedit打开注册表

    software-GNU-Emacs 在右边新建字符串值 右击修改把你想要home在的目录进去,例如我的是D:/Emacs/emacs-23.2

    安装cedet和ecb

    下载cedet-1.0  ecb-2.40目前是最新的

     

     

    Windows 下编译安装,在命令行下,进入到 cedit 的目录,输入命令:

    > path/to/emacs/bin/emacs.exe -Q -l cedet-build.el -f cedet-build

    在.emacs中加入

     

    ;; Load CEDET. ;; See cedet/common/cedet.info for configuration details. (load-file "D:/Emacs/emacs-23.2/cedet-1.0/common/cedet.el") (semantic-load-enable-minimum-features) (semantic-load-enable-code-helpers) (semantic-load-enable-guady-code-helpers) (semantic-load-enable-excessive-code-helpers) (semantic-load-enable-s-debugging-helpers) ;; Enable EDE (Project Management) features (global-ede-mode 1) (global-set-key [f4] 'speedbar)

     

    把ecb解压到一个目录里

    修改一些文件

    1、ecb-analyse.e -(require 'semantic-analyze) +(require 'semantic/analyze) (require 'ecb-layout) (require 'ecb-common-browser) (require 'ecb-method-browser) 2、ecb-cedet-wrapper.el (require 'semantic) -(require 'semantic-ctxt) -(require 'semantic-analyze) -(require 'semanticdb) -(require 'semanticdb-find) -(require 'semanticdb-mode) +(require 'semantic/ctxt) +(require 'semantic/analyze) +(require 'semantic/db) +(require 'semantic/db-find) +(require 'semantic/db-mode) (defconst ecb-semantic-2-loaded (string-match "^2" semantic-version)) 3、ecb-method-browser.el (require 'ecb-speedbar) (require 'ecb-cedet-wrapper) -;; This loads the semantic-setups for the major-modes. -(require 'semantic-load) ;; various loads (require 'assoc) 减号代表要修改的 或者删除的

    .emacs中添加

     ;;;;ECB (add-to-list 'load-path "D:/Emacs/emacs-23.2/ecb-2.40") (require 'ecb) ;;;;禁止每日提醒 (setq ecb-tip-of-the-day nil) ;;;; 各窗口间切换 (global-set-key [M-left] 'windmove-left) (global-set-key [M-right] 'windmove-right) (global-set-key [M-up] 'windmove-up) (global-set-key [M-down] 'windmove-down)

    emacs只是一个编辑器,要想编译c++程序必须要有编译器

    下载dev-cpp安装,它的编译器是mingw,正是我们想要的,我安装在D:/DEV-CPP下

    自己安装gcc-core  gdb g++之类的话会很麻烦,这里用了一个偷懒的办法。

    配置.emacs,用dev-cpp里面的编译器为emacs工作

    (setq default-directory "D:/DEV-CPP/Bin") ;;=================================== ;;设置编译器========================== ;;=================================== ;;(setq compile-command (concat "D:/DEV-CPP/bin/g++ -g " "/"" buffer-file-name "/"")) (global-set-key (kbd "<f7>") 'smart-compile) (defun smart-compile() ;; "比较智能的C/C++编译命令 ;;如果当前目录有makefile则用make -k编译,否则,如果是 ;;处于c-mode,就用gcc -Wall编译,如果是c++-mode就用 g++ -Wall编译" (interactive) ;; 查找 Makefile (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 是否是已知的可编译的模式 (if (null (buffer-file-name (current-buffer))) (message "Buffer not attached to a file, won't compile!") (if (eq major-mode 'c-mode) (setq command (concat "D:/DEV-CPP/bin/gcc.exe -Wall -o " ;;你要明确知道自己的编译器在 哪里, (file-name-sans-extension ;;这样,用你的 gcc.exe的地址代替这里的D:/Dev-Cpp/bin/gcc.exe (file-name-nondirectory buffer-file-name)) ;;注意,这里的路径的斜杠 和vista的习惯相反,你要注意修改 " " (file-name-nondirectory buffer-file-name) " -g -lm ")) (if (eq major-mode 'c++-mode) (setq command (concat "D:/DEV-CPP/bin/g++.exe -Wall -o " ;;还有这里的g++,也同gcc一样... (file-name-sans-extension (file-name-nondirectory buffer-file-name)) " " (file-name-nondirectory buffer-file-name) " -g -lm ")) (message "Unknow mode, won't compile!"))))) (if (not (null command)) (let ((command (read-from-minibuffer "Compile command: " command))) (compile command)))))

    上面default-directory是让emacs找到devcpp的编译器

    下面是配置一个快捷键f7,省得每次都 gcc -Wall -g exp.cpp -o exp

    到这里就应该可以调用以下的命令了

    ecb-activiate 来激活ecb,可以看到ecb窗口

    打开一个cpp文件 按下f7应该可以编译文件

    M-x gdb应该可以进入调试模式

    下面是代码折叠的配置

    ;;; hide-show (setq hs-allow-nesting t) (add-hook 'c-mode-common-hook (lambda () (hs-minor-mode 1) )) (add-hook 'emacs-lisp-mode-hook (lambda() (hs-minor-mode 1))) (add-hook 'tcl-mode-hook (lambda () (hs-minor-mode 1) )) (define-key hs-minor-mode-map [?/C-/ ?H] 'hs-hide-all) (define-key hs-minor-mode-map [?/C-/ ?S] 'hs-show-all) (define-key hs-minor-mode-map [?/C-/ ?h] 'hs-hide-block) (define-key hs-minor-mode-map [?/C-/ ?s] 'hs-show-block) (define-key hs-minor-mode-map [?/C-/ ?l] 'hs-hide-level) (define-key hs-minor-mode-map [?/C-/ ?t] 'hs-toggle-hiding)

     

    显示行号,把下面的代码粘贴保存为linum.el,保存到site-lisp下

    ;;; linum.el --- Display line numbers to the left of buffers ;; Copyright (C) 2007, 2008 Markus Triska ;; Author: Markus Triska <markus.triska@gmx.at> ;; Keywords: convenience ;; This file 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 3, or (at your option) ;; any later version. ;; This file 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 GNU Emacs; see the file COPYING. If not, write to ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, ;; Boston, MA 02110-1301, USA. ;;; Commentary: ;; Display line numbers for the current buffer. Copy linum.el to your ;; load-path and add to your .emacs: ;; (require 'linum) ;; Then toggle display of line numbers with M-x linum-mode. To enable ;; line numbering in all buffers, use M-x global-linum-mode. ;;; Code: (defconst linum-version "0.9wza") (defvar linum-overlays nil "Overlays used in this buffer.") (defvar linum-available nil "Overlays available for reuse.") (defvar linum-before-numbering-hook nil "Functions run in each buffer before line numbering starts.") (mapc #'make-variable-buffer-local '(linum-overlays linum-available)) (defgroup linum nil "Show line numbers to the left of buffers" :group 'convenience) ;;;###autoload (defcustom linum-format 'dynamic "Format used to display line numbers. Either a format string like /"}/", 'dynamic to adapt the width as needed, or a function that is called with a line number as its argument and should evaluate to a string to be shown on that line. See also `linum-before-numbering-hook'." :group 'linum :type 'sexp) (defface linum '((t :inherit (shadow default))) "Face for displaying line numbers in the display margin." :group 'linum) (defcustom linum-eager t "Whether line numbers should be updated after each command. The conservative setting `nil' might miss some buffer changes, and you have to scroll or press C-l to update the numbers." :group 'linum :type 'boolean) (defcustom linum-delay nil "Delay updates to give Emacs a chance for other changes." :group 'linum :type 'boolean) ;;;###autoload (define-minor-mode linum-mode "Toggle display of line numbers in the left marginal area." :lighter "" ; for desktop.el (if linum-mode (progn (if linum-eager (add-hook 'post-command-hook (if linum-delay 'linum-schedule 'linum-update-current) nil t) (add-hook 'after-change-functions 'linum-after-change nil t)) (add-hook 'window-scroll-functions 'linum-after-scroll nil t) ;; mistake in Emacs: window-size-change-functions cannot be local (add-hook 'window-size-change-functions 'linum-after-size) (add-hook 'change-major-mode-hook 'linum-delete-overlays nil t) (add-hook 'window-configuration-change-hook 'linum-after-config nil t) (linum-update-current)) (remove-hook 'post-command-hook 'linum-update-current t) (remove-hook 'post-command-hook 'linum-schedule t) (remove-hook 'window-size-change-functions 'linum-after-size) (remove-hook 'window-scroll-functions 'linum-after-scroll t) (remove-hook 'after-change-functions 'linum-after-change t) (remove-hook 'window-configuration-change-hook 'linum-after-config t) (remove-hook 'change-major-mode-hook 'linum-delete-overlays t) (linum-delete-overlays))) ;;;###autoload (define-globalized-minor-mode global-linum-mode linum-mode linum-on) (defun linum-on () (unless (minibufferp) (linum-mode 1))) (defun linum-delete-overlays () "Delete all overlays displaying line numbers for this buffer." (mapc #'delete-overlay linum-overlays) (setq linum-overlays nil) (dolist (w (get-buffer-window-list (current-buffer) nil t)) (set-window-margins w 0))) (defun linum-update-current () "Update line numbers for the current buffer." (linum-update (current-buffer))) (defun linum-update (buffer) "Update line numbers for all windows displaying BUFFER." (with-current-buffer buffer (when linum-mode (setq linum-available linum-overlays) (setq linum-overlays nil) (save-excursion (mapc #'linum-update-window (get-buffer-window-list buffer nil 'visible))) (mapc #'delete-overlay linum-available) (setq linum-available nil)))) (defun linum-update-window (win) "Update line numbers for the portion visible in window WIN." (goto-char (window-start win)) (let ((line (line-number-at-pos)) (limit (window-end win t)) (fmt (cond ((stringp linum-format) linum-format) ((eq linum-format 'dynamic) (let ((w (length (number-to-string (count-lines (point-min) (point-max)))))) (concat "%" (number-to-string w) "d"))))) (width 0)) (run-hooks 'linum-before-numbering-hook) ;; Create an overlay (or reuse an existing one) for each ;; line visible in this window, if necessary. (while (and (not (eobp)) (<= (point) limit)) (let* ((str (if fmt (propertize (format fmt line) 'face 'linum) (funcall linum-format line))) (visited (catch 'visited (dolist (o (overlays-in (point) (point))) (when (string= (overlay-get o 'linum-str) str) (unless (memq o linum-overlays) (push o linum-overlays)) (setq linum-available (delete o linum-available)) (throw 'visited t)))))) (setq width (max width (length str))) (unless visited (let ((ov (if (null linum-available) (make-overlay (point) (point)) (move-overlay (pop linum-available) (point) (point))))) (push ov linum-overlays) (overlay-put ov 'before-string (propertize " " 'display `((margin left-margin) ,str))) (overlay-put ov 'linum-str str)))) (forward-line) (setq line (1+ line))) (set-window-margins win width))) (defun linum-after-change (beg end len) ;; update overlays on deletions, and after newlines are inserted (when (or (= beg end) (= end (point-max)) ;; TODO: use string-match-p with CVS or new release (string-match "/n" (buffer-substring-no-properties beg end))) (linum-update-current))) (defun linum-after-scroll (win start) (linum-update (window-buffer win))) (defun linum-after-size (frame) (linum-after-config)) (defun linum-schedule () ;; schedule an update; the delay gives Emacs a chance for display changes (run-with-idle-timer 0 nil #'linum-update-current)) (defun linum-after-config () (walk-windows (lambda (w) (linum-update (window-buffer w))) nil 'visible)) (provide 'linum) ;;; linum.el ends here

    在.emacs中加上

    (require 'linum)(global-linum-mode 1) 

     

    代码自动补全 保存以下代码到site-lisp,名称为yasnippet-bundle.el

     在.emacs中加入(require 'yasnippet-bundle) 具体的用法上百度找视频

     

     

    其他一些配置

    (tool-bar-mode nil)(scroll-bar-mode nil)

    ;;yes no用y n代替(fset 'yes-or-no-p 'y-or-n-p);;不要生成临时文件(setq-default make-backup-files nil)

     


    最新回复(0)