有没有一个很好的方法来做Emacs项目?

我使用emacs做一些编码和文本编辑。当我创建一个新的编码项目时,我只需创建一个新文件夹,并在其中添加源代码。 问题是,对于多文件夹,很难改回 顶部,并运行makefile。 是否有任何好的方法来进行项目管理,如eclipse或 其他IDE?     
已邀请:
我通常不再在emacs中编译,但为什么不能在缓冲区中运行shell只是为了运行make。将该shell保留在顶级目录中。 至于项目管理,您在寻找什么功能?     
我知道你的问题。如果Makefile与源文件夹在同一个文件夹中,并且您在源缓冲区中,那么'compile'将正确构建。 但是如果您的源位于不同的文件夹中,则emacs无法找到Makefile。 一种解决方案是通过将'default-directory'变量设置为每个源文件中的文件变量来指定Makefile的位置。 您可以通过在文件顶部添加这样的行(并重新加载)来完成此操作。
// -*- mode: C++; default-directory: "c:/somewhere/yourmakefiledirectory/" -*-
    
下面是;;我的.emacs文件的编译部分。我使用CTRL + F7进行make,使用F7进行make clean。它将在当前目录中搜索,然后在...中依次查找名为“Makefile”的文件以运行make。 也不是F8将源窗口跳转到第一个错误而CTRL + F8会将您带到上一个错误。 (顺便说一下,如果你认为这很棒,你应该看看我为GDB集成做了什么)...... :)
;; Compilation
(setq compilation-scroll-output 1) ;; automatically scroll the compilation windo
w
(setq compilation-window-height 10) ;; Set the compilation window height...
(setq compilation-finish-function ;; Auto-dismiss compilation buffer...
      (lambda (buf str)
        (if (string-match "exited abnormally" str)
            (message "compilation errors, press F6 to visit")
          ; no errors, make the compilation window go away after 2.5 sec
          (run-at-time 2.5 nil 'delete-windows-on buf)
          (message "No compilation errors!"))))

(require 'cl) ; If you don't have it already
(defun* get-closest-pathname (&optional (file "Makefile"))
  "This function walks up the current path until it finds Makefile and then retu
rns the path to it."
  (let ((root (expand-file-name "/")))
    (expand-file-name file
              (loop
            for d = default-directory then (expand-file-name ".." d)
            if (file-exists-p (expand-file-name file d))
            return d
            if (equal d root)
           return nil))))

(defun my-compile-func ()
  "This function does a compile."
  (interactive)
  (compile (format "make -C %s" (file-name-directory (get-closest-pathname)))))

(defun my-compile-clean-func ()
  "This function does a clean compile."
  (interactive)
  (compile (format "make -C %s clean" (file-name-directory (get-closest-pathname
)))))

(defun my-compile-package-func ()
  "This function builds an Endura package."
  (interactive)
  (compile (format "make -C %s package" (file-name-directory (get-closest-pathna
me)))))

(global-set-key [f7] 'my-compile-clean-func)
(global-set-key [C-f7] 'my-compile-func)
(global-set-key [S-f7] 'my-compile-package-func)
(global-set-key [f8] 'next-error)
(global-set-key [C-f8] 'previous-error)
    
从根目录只需
M-x compile
一次。这将创建一个
*compilation*
缓冲区,它将记住调用它的目录和参数。 然后当你想重新编译时,只需发出
M-x recompile
。这适用于任何地方。它会恢复原始的
*compilation*
缓冲区并使用该缓冲区中存储的目录来查找Makefile。 还有其他方法可以从项目的根目录外部发出编译,但我想我会指出这一点,因为它开箱即用,没有自定义。许多其他反应使得解决方案听起来比现在更加复杂。 编译缓冲区提示 如果在编译缓冲区中键入
C-c C-f
,它将启用
next-error-follow-minor-mode
,这样当您在编译缓冲区的错误之间导航时,第二个窗口将在其原始源缓冲区中显示错误。
M-n
M-p
将在编译缓冲区的错误之间移动。 如果您已经在源缓冲区中,并且想要在那里之间导航,请键入
M-g n
M-g p
。 语法错误突出显示 键入
M-x flymake-mode
可在键入时进行即时语法检查。它将以红色突出显示语法错误。将鼠标悬停在上方会显示错误消息。 要使flymake正常工作,必须在makefile中添加check-syntax规则。 C ++示例:
check-syntax:
    g++ -o nul -S ${CXXFLAGS} ${CHK_SOURCES}
此规则检查文件的语法,但不编译它,因此速度很快。     
我使用CEDET包中的EDE - 它可以维护不同类型的项目。我用它来使用CMake,以及自定义编译命令(你可以在这里找到它 - 参见MyCompile函数)     
我最近开始使用project-root来管理我的各种目录树。我现在将F5绑定到(with-project-root(compile))并且默认目录自动设置为我在.emacs中指定的任何项目的根目录,基于我正在调用的任何缓冲区编译自。     
我不确定你在问什么,但你可能正在寻找Speedbar。     
您可以使用桌面书签,Dired书签或Bookmark-List书签来组织项目 - 请参阅书签+。 另请参阅:Icicles支持项目以获得更多选项。 bookmarksbookmark     
取决于语言。 JDE是一个很好的Java环境,Distel是一个很好的Erlang环境。我相信其他平台也有良好的环境。但是,在整个主板上,您将需要在emacs中进行比在Eclipse之类的IDE中更多的配置。不过,国际海事组织的回报是值得的。     
提示输入编译命令时如何输入以下内容: “cd< root&gt ;; make” 如果经常键入是一件麻烦事,可以在“compile-command”变量中设置它 - 虽然在键入一次后会在会话中记住它。     
当我用Java做这个时,我使用了ANT,ANT用“-find”开关优雅地处理了这个问题。 它实际上是在build.xml文件的当前目录中查找,直到找到它为止。非常方便,特别是在Java项目中,因为它们强制执行目录结构。 对于Make,我会创建一个类似的替换:
#!/bin/sh
# mymake -- my "hunt the makefile" make command
if [ -f Makefile ]
then
    exec make
else
    cur=`pwd`
    if [ $cur = "/" ]
    then
        echo "Can not find Makefile"
        exit 1
    fi
    newdir=`dirname $cur`
    cd $newdir
    exec mymake
fi
    
我会用eproject; http://github.com/jrockway/eproject 这是SO的一个例子:在某处有一个很好的Emacs项目管理吗? 基本上,它统一了CEDET,项目根等功能。您可以通过多种方式声明项目定义,并通过统一的API访问数据。它还附带一些不错的糖,包括ibuffer集成。 (按项目过滤ibuffer,查看缓冲区名称旁边的项目名称等]     

要回复问题请先登录注册