emacs lisp脚本优化帮助请求 [英] emacs lisp scripting optimization help request

查看:93
本文介绍了emacs lisp脚本优化帮助请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习emacs lisp,并且正在尝试使用它编写脚本。我写了一个脚本,它很好用,但是我只是觉得我可以用eashs lisp在bash中做很多事情。

I'm learning emacs lisp and I'm trying to script using it. I wrote a script and it works fine but I just think there are a lot of things I make in bash that I can do in emacs lisp instead.

在这里很重要: 我不确定我的启动过程是否正确

请建议/向我展示脚本脚本的简洁方式(例如):

Please suggest / show me the lisp way of scripting on my script (as example) :

#!/usr/bin/emacs --script
(message "Vision synchronization \n")
(let ((default-directory "/home/vision/"))
  (shell-command "git pull;")
  (princ (shell-command-to-string "git fetch upstream;git merge upstream/master;"))
  (princ (start-process "Vision push \n" "git" "git" "push")))

(message "Gentoo-haskell synchronization \n")
(let ((default-directory "/home/gentoo-haskell/"))
  (shell-command "git pull;")
  (princ (shell-command-to-string "git fetch upstream;git merge upstream/master;"))
  (princ (start-process "Gentoo-haskell push \n" "git" "git" "push")))

(message "Nengraphy synchronization \n")
(let ((default-directory "/home/nengraphy/"))
    (princ (start-process "Nengraphy pull \n" "git" "git" "pull")))

(message "Gentoo synchronization \n")
(let ((default-directory "/usr/portage/"))
  (message "Gentoo rsync (New files will be added, deprecated files will be deleted) : \n")
  (princ (shell-command-to-string "rsync --recursive --links --safe-links --perms --times --compress --force --whole-file --delete --timeout=180 --exclude=/.git --exclude=/metadata/cache/ --exclude=/distfiles --exclude=/local --exclude=/packages rsync://209.177.148.226/gentoo-portage/ /usr/portage/"))
  (message "We want to make extra-sure that we don't grab any metadata, since we don't keep metadata for the gentoo.org tree (space reasons)")
  (shell-command "[ -e metadata/cache ] && rm -rf metadata/cache")
  (shell-command "[ -e metadata/md5-cache ] && rm -rf metadata/md5-cache")
  (message "the rsync command wiped our critical .gitignore file, so recreate it.")
  (shell-command "echo \"distfiles/*\" > /usr/portage/.gitignore")
  (shell-command "echo \"packages/*\" >> /usr/portage/.gitignore")
  (message "profile formats fix")
  (shell-command "echo \"profile-formats = portage-1\" >> /usr/portage/metadata/layout.conf")
  (message "\"git add .\" will record all the changes to local files the git repo. So there must be no stray files.")
  (shell-command "if [ ! -d profiles/package.mask ]
  then
    mv profiles/package.mask profiles/package.mask.bak || exit 4
    install -d profiles/package.mask || exit 4
    mv profiles/package.mask.bak profiles/package.mask/gentoo || exit 4
  fi")
  (princ (shell-command-to-string "git add ."))
  (message "create a commit")
  (shell-command "git commit -a -m \"gentoo updates `date` update\"")
  (message "push these changes up.")
  (princ (shell-command-to-string "git push origin master")))

(message "Gentoo verification \n")
(princ (shell-command-to-string "emerge --sync;"))

(message "Layman synchronization \n")
(princ (shell-command-to-string "layman -S;"))

谢谢!

推荐答案

这实际上只是一个使用笨拙的elisp包装的bash脚本。以这种方式使用elisp没有优势。在开始使用elisp实际计算某些东西之前,您可能应该坚持使用bash。

This is really just a bash script using some awkward elisp wrapping. There is no advantage to using elisp this way. Until you start using elisp to actually compute something, you should probably stick with bash.

您可以使用emacs编写脚本来打开文本文件并修改文本,就像对sed或awk所做的那样。那会更有意义。在这一点上,对我来说,使用elisp进行此操作比查找awk语法要快。

You could use emacs to script opening text files and modifying the text, like what you might do with sed or awk. That would make a little more sense. At this point, it would be faster for me to do this with elisp than to look up the awk syntax.

您确实必须从某个地方开始,但是您正在做的事情对于elisp非常尴尬。最好是通过利用语言的优势来学习,而不是强迫它去做并非真正为之的事情。

You do have to start somewhere, but what you are doing is a very awkward fit for elisp. Better to learn by working with the strengths of a language than by forcing it to do something it is not really made for.

此外,启动过程在一个脚本。它会在emacs中启动一个进程,以允许进行持续的通信,而这在脚本中是不需要或不需要的。

Also, start-process does not make sense in a script. It starts a process within emacs to allow for ongoing communication, which you do not want or need in a script.

这篇关于emacs lisp脚本优化帮助请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆