开发者

Emacs subprocesses and filepaths in their arguments

开发者 https://www.devze.com 2023-02-09 18:08 出处:网络
I\'m trying to create some short-cut keys to start and stop the \"paster serve\" command used in pyramid projects.Here\'s my elisp code:

I'm trying to create some short-cut keys to start and stop the "paster serve" command used in pyramid projects. Here's my elisp code:

(defun search-for-file (file 开发者_如何学Cdir)
  "Recursively searches up the directory tree for a given filename"
  (if (equal "/" dir)
      nil
    (if (member file (directory-files dir))
        (concat (file-name-as-directory dir) file)
      (progn
        (cd-absolute dir)
        (cd "..")
        (search-for-file file default-directory)))))

(defun paster-serve-start ()
  (interactive)
  (progn
    (start-process
     "paster-serve" "server"
     "paster" "serve" (search-for-file "development.ini" ".") "--reload" "-v")
    (switch-to-buffer "server")))

(defun paster-serve-stop ()
  (interactive)
  (progn
    (setq proc (get-process "paster-serve"))
    (setq buf (get-buffer "server"))
    (quit-process proc)
    (kill-buffer buf)))

(define-prefix-command 'paster-map)
(global-set-key (kbd "C-p") 'paster-map)
(define-key paster-map (kbd "s") 'paster-serve-start)
(define-key paster-map (kbd "e") 'paster-serve-stop)

These functions work as I expect from a buffer which has default-directory set to where development.ini exists (e.g. ~/myproject); however, I was hoping to have this work when I was in a directory below the project's base directory (e.g. ~/myproject/myproject/templates) - when I try to run the process from a directory below where development.ini resides, I get this error:

IOError: File '/home/myuser/myproject/~/myproject/development.ini' not found

Are there any enlightened emacs masters who can shed some light on what I'm doing wrong here?


I'm a bit wary of all those cd functions. Try this alternate definition of search-for-file, based on a similar function in project-local-variables.el:

(defun search-for-file (file dir)
  "Look up the file in and above `dir'."
 (let ((f (expand-file-name file dir))
       (parent (file-truename (expand-file-name ".." dir))))
   (cond ((string= dir parent) nil)
         ((file-exists-p f) f)
         (t (search-for-file file parent)))))
0

精彩评论

暂无评论...
验证码 换一张
取 消