(这个估计会比较冷)Terminal + emacs-nw VS emacs + eshell?

不同视角、不同观点、深度探讨,禁止人品和道德攻击
zhangsong023
帖子: 768
注册时间: 2006-09-20 19:56

#31

帖子 zhangsong023 » 2007-11-17 17:24

我不用sudo,对于apt,可以自己写一个函数,pcomplete/apt。
参见pcomplete/make,在pcmpl-gnu.el中。
再强调一下,要把eshell用爽一定要熟悉elisp语言。
vupiggy
帖子: 89
注册时间: 2006-03-19 18:25
来自: FZ->TJ->PEK->AMS->MTL

#32

帖子 vupiggy » 2007-11-18 1:41

啊,就是flymake。这个对于高手来说的确是鸡肋了。不过对于普通程序员来说真是听管事儿的。我记得我和我朋友讨论过这个问题,大致结论是如果你能一气写200行程序,一次性编译通过已经很厉害了。后来我的一个老师也说了差不多同样的话,大意是150行的程序一次性编译通过的做我的RA我非常欢迎。flymake其实是为了纠正一些低级的笔误和粗心大意造成的错误,省得当你写了1000多行以后make一次报无数的错误,然后不停地改不停地make。对于普通程序员来说还是很友好的。是有些bug,不过基本不影响使用。
morningboat
帖子: 179
注册时间: 2006-06-09 20:31

#33

帖子 morningboat » 2007-11-18 3:42

emacs + multi-tab + multiple shells 很方便, 不太需要其他的console。 同时可以用ido找找buffer, dired看看目录, killing ring查查剪贴历史,flymaker揪揪错, 再加上些各种mode, 处理script是很无敌了。找一个theme后看的也可以很舒服。
至于console下的话,emacs -nw用在远程登陆而没有gui接口比较好吧,比方登陆virtual server, 用一个emacs就可以多线程处理多窗口的console了。
aof
帖子: 12
注册时间: 2005-03-31 22:32

#34

帖子 aof » 2007-11-18 11:07

urxvt的中文显示不应该是这样的。我用的是下面的设置,好像没有你的情况。

URxvt*font: xft:Monospace:pixelsize=12,\
xft:NSimSun,\
xft:PMingLiU
头像
stlxv
论坛版主
帖子: 8275
注册时间: 2006-05-03 0:39
来自: المريخ

#35

帖子 stlxv » 2007-11-18 11:26

zhangsong023 写了:
麻烦vupiggy和zhangsong023把eshell的配置贴来看看,:)

BTW,没想到这贴并不冷哈,大家好好交流呀,千万别搞成VI VS EMACS的圣战,大牛们都争论了几十年的东西,都没有结果,我等小辈还是好好学习点东西吧。等大家用到大牛的水平再争论也不迟呀。我只知道我现在连 EMACS的最基本的功能都没有用到多少,包括eshell呵呵。连elisp都不会,我不会与人争论的:(
我的配置很长,如下:

代码: 全选

;; Zhangsong 
;; zjs-eshell.el
(require 'eshell)

(setq eshell-cp-interactive-query t
      eshell-ln-interactive-query t
      eshell-mv-interactive-query t
      eshell-rm-interactive-query t
      eshell-ls-use-in-dired t
      eshell-mv-overwrite-files nil)

;; 启动设置
(defun zjs-eshell-setup ()
  (define-key eshell-mode-map "\t" 'pcomplete-list)
  (define-key eshell-mode-map (kbd "s-a") 'eshell-maybe-bol)
  (eldoc-mode 1))
(add-hook 'eshell-mode-hook 'zjs-eshell-setup)

;; 自定义补全规则
(setq eshell-cmpl-cycle-completions nil)
(defadvice pcomplete (around avoid-remote-connections activate)
  (let ((file-name-handler-alist (copy-alist file-name-handler-alist)))
    (setq file-name-handler-alist
          (delete (rassoc 'tramp-completion-file-name-handler
                          file-name-handler-alist) file-name-handler-alist))
    ad-do-it))

;; 自定义提示符
(setq zjs-emacs-name "GNU Emacs-22.1")
(defun zjs-eshell-prompt ()
  "An Eshell prompt looks very cool."
  (let ((user (or (getenv "USER") user-login-name "ted"))
        (wd (eshell/pwd))
        (host (car (split-string (or (getenv "HOST")
                                     system-name
                                     "unknown")
                                 "\\.")))
        (term (concat zjs-emacs-name (format " PID %d" (emacs-pid))))
        (time (let ((time-1 (downcase (format-time-string "%Y.%m.%d %A %p %l:%M:%S"))))
                (if (char-equal (aref time-1 0) ?\ )
                    (substring time-1 1)
                  time-1)))
        ;; based on `eshell-exit-success-p'
        (r (if (save-match-data
                 (string-match "#<\\(Lisp object\\|function .*\\)>"
                               (or eshell-last-command-name "")))
               (format "%s" eshell-last-command-result)
             (number-to-string eshell-last-command-status)))
        (h (number-to-string (+ 1 (ring-length eshell-history-ring))))
        (char (if (= (user-uid) 0) "#" "$")))
    (concat "\n" user
            "\n"
            "In " wd
            "\n"
            "On " host "'s " term
            "\n"
            "At " time
            "\n"
            "(h=" h ", "
            "r=" r ")"
            " " char " ")))

(setq eshell-prompt-regexp
      (mapconcat
       '(lambda (str) (concat "\\(" str "\\)"))
       '("^[^#$]* [#$] "                ; default
         "^\\(mysql\\|[ ]\\{4\\}[-"'`]\\)> "
         "^>>> "                        ; python
         "^ftp> "
         )
       "\\|"))
(setq eshell-prompt-function 'zjs-eshell-prompt)

;; 在ls命令的结果列表中,用回车键和鼠标中键访问目录和文件,来自emacs-wik,感谢ted。
(eval-after-load "em-ls"
  '(progn
     (defun ted-eshell-ls-find-file-at-point ()
       (interactive)
       (let ((fname (buffer-substring-no-properties
                     (previous-single-property-change (point) 'help-echo)
                     (next-single-property-change (point) 'help-echo))))
         ;; Remove any leading whitespace, including newline that might
         ;; be fetched by buffer-substring-no-properties
         (setq fname (replace-regexp-in-string "^[ \t\n]*" "" fname))
         ;; Same for trailing whitespace and newline
         (setq fname (replace-regexp-in-string "[ \t\n]*$" "" fname))
         (cond
          ((equal "" fname)
           (message "No file name found at point"))
          (fname
           (find-file fname)))))
     
     (defun pat-eshell-ls-find-file-at-mouse-click (event)
       "Middle click on Eshell's `ls' output to open files.
 From Patrick Anderson via the wiki."
       (interactive "e")
       (ted-eshell-ls-find-file-at-point (posn-point (event-end event))))

     (let ((map (make-sparse-keymap)))
       (define-key map (kbd "RET")      'ted-eshell-ls-find-file-at-point)
       (define-key map (kbd "<return>") 'ted-eshell-ls-find-file-at-point)
       (define-key map (kbd "<mouse-2>") 'pat-eshell-ls-find-file-at-mouse-click)
       (defvar ted-eshell-ls-keymap map))

     (defadvice eshell-ls-decorated-name (after ted-electrify-ls activate)
       "Eshell's `ls' now lets you click or RET on file names to open them."
       (add-text-properties 0 (length ad-return-value)
                            (list 'help-echo "RET, mouse-2: visit this file"
                                  'mouse-face 'highlight
                                  'keymap ted-eshell-ls-keymap)
                            ad-return-value)
       ad-return-value)))

;; 不用圆括号时eldoc也能工作,有一点bug,况且是鸡肋,干掉。
;; (defadvice eldoc-fnsym-in-current-sexp (around eldoc-fnsym-in-current-sexp-or-command activate)
;;   ad-do-it
;;   (if (and (not ad-return-value)
;;            (eq major-mode 'eshell-mode))
;;       (save-excursion
;;         (goto-char eshell-last-output-end)
;;         (setq ad-return-value (eldoc-current-symbol)))))

;; 使用"emacs"命令在当前的emacs中打开文件
(defun eshell/emacs (&rest args)
  "Open a file in emacs. Some habits die hard."
  (if (null args)
      ;; If I just ran "emacs", I probably expect to be launching
      ;; Emacs, which is rather silly since I'm already in Emacs.
      ;; So just pretend to do what I ask.
      (bury-buffer)
    ;; We have to expand the file names or else naming a directory in an
    ;; argument causes later arguments to be looked for in that directory,
    ;; not the starting directory
    (mapc #'find-file (mapcar #'expand-file-name (eshell-flatten-list (reverse args))))))

;; 在apt包管理机制下的包查看工具
(defun eshell/deb (&rest args)
  (eshell-eval-using-options
   "deb" args
   '((?f "find" t find "list available packages matching a pattern")
     (?i "installed" t installed "list installed debs matching a pattern")
     (?l "list-files" t list-files "list files of a package")
     (?s "show" t show "show an available package")
     (?v "version" t version "show the version of an installed package")
     (?w "where" t where "find the package containing the given file")
     (nil "help" nil nil "show this usage information")
     :show-usage)
   (eshell-do-eval
    (eshell-parse-command
     (cond
      (find
       (format "apt-cache search %s" find))
      (installed
       (format "dlocate -l %s | grep '^.i'" installed))
      (list-files
       (format "dlocate -L %s | sort" list-files))
      (show
       (format "apt-cache show %s" show))
      (version
       (format "dlocate -s %s | egrep '^(Package|Status|Version):'" version))
      (where
       (format "dlocate %s" where))))
    t)))

;; 删除当前目录下的文件名以~结尾备份文件
(defun eshell/ro ()
  "Delete files matching pattern ".*~" and "*~""
  (eshell/rm (directory-files "." nil "^\\.?.*~$" nil)))

;; 如果找到了info项,则打开该项,否则回到eshell
(defun eshell/info (subject)
  "Read the Info manual on SUBJECT."
  (let ((buf (current-buffer)))
    (Info-directory)
    (let ((node-exists (ignore-errors (Info-menu subject))))
      (if node-exists
          0
        ;; We want to switch back to *eshell* if the requested
        ;; Info manual doesn't exist.
        (switch-to-buffer buf)
        (eshell-print (format "There is no Info manual on %s.\n"
                              subject))
        1))))

(defun tyler-eshell-view-file (file)
  "A version of `view-file' which properly respects the eshell prompt."
  (interactive "fView file: ")
  (unless (file-exists-p file) (error "%s does not exist" file))
  (let ((had-a-buf (get-file-buffer file))
        (buffer (find-file-noselect file)))
    (if (eq (with-current-buffer buffer (get major-mode 'mode-class))
            'special)
        (progn
          (switch-to-buffer buffer)
          (message "Not using View mode because the major mode is special"))
      (let ((undo-window (list (window-buffer) (window-start)
                               (+ (window-point)
                                  (length (funcall eshell-prompt-function))))))
        (switch-to-buffer buffer)
        (view-mode-enter (cons (selected-window) (cons nil undo-window))
                         'kill-buffer)))))
(defun eshell/less (&rest args)
  "Invoke `view-file' on a file. "less +42 foo" will go to line 42 in
    the buffer for foo."
  (while args
    (if (string-match "\\`\\+\\([0-9]+\\)\\'" (car args))
        (let* ((line (string-to-number (match-string 1 (pop args))))
               (file (pop args)))
          (tyler-eshell-view-file file)
          (goto-line line))
      (tyler-eshell-view-file (pop args)))))
(defalias 'eshell/more 'eshell/less)

;; 如果光标在提示符处,移到其到行首,否则,移到提示符处。
(defun eshell-maybe-bol ()
  (interactive)
  (let ((p (point)))
    (eshell-bol)
    (if (= p (point))
        (beginning-of-line))))

;; Here’s how to compile in the background, also by Kai.
(defun eshell/ec (&rest args)
  "Use `compile' to do background makes."
  (if (eshell-interactive-output-p)
      (let ((compilation-process-setup-function
             (list 'lambda nil
                   (list 'setq 'process-environment
                         (list 'quote (eshell-copy-environment))))))
        (compile (eshell-flatten-and-stringify args))
        (pop-to-buffer compilation-last-buffer))
    (throw 'eshell-replace-command
           (let ((l (eshell-stringify-list (eshell-flatten-list args))))
             (eshell-parse-command (car l) (cdr l))))))
(put 'eshell/ec 'eshell-no-numeric-conversions t)

;; 整合eshell和bookmark
(require 'bookmark)
(defun pcomplete/eshell-mode/bmk ()
  "Completion for `bmk'"
  (pcomplete-here (bookmark-all-names)))
(defun eshell/bmk (&rest args)
  "Integration between EShell and bookmarks.
For usage, execute without arguments."
  (setq args (eshell-flatten-list args))
  (let ((bookmark (car args))
        filename name)
    (cond
     ((eq nil args)
      (format "Usage: bmk BOOKMARK to change directory pointed to by BOOKMARK
    or bmk . BOOKMARK to bookmark current directory in BOOKMARK.
Completion is available."))
     ((string= "." bookmark)
      ;; Store current path in EShell as a bookmark
      (if (setq name (car (cdr args)))
          (progn
            (bookmark-set name)
            (bookmark-set-filename name (eshell/pwd))
            (format "Saved current directory in bookmark %s" name))
        (error "You must enter a bookmark name")))
     (t
      ;; Assume the user wants to go to the path pointed out by a bookmark.
      (if (setq filename (cdr (car (bookmark-get-bookmark-record bookmark))))
          (if (file-directory-p filename)
              (eshell/cd filename)
            ;; TODO: Handle this better and offer to go to directory
            ;; where the file is located.
            (error "Bookmark %s points to %s which is not a directory" 
                   bookmark filename))
        (error "%s is not a bookmark" bookmark))))))

;; Here's a little trick to get "ssh" in eshell to launch ssh in a new
;; screen when running under GNU screen, or a new xterm when running
;; under X. Otherwise, ssh is run in a new term buffer.
(defun eshell/ssh (&rest args)
  "Secure shell"
  (let ((cmd (eshell-flatten-and-stringify
              (cons "ssh" args)))
        (display-type (framep (selected-frame))))
    (cond
     ((and
       (eq display-type 't)
       (getenv "STY"))
      (send-string-to-terminal (format "\033]83;screen %s\007" cmd)))
     ((eq display-type 'x)
      (eshell-do-eval
       (eshell-parse-command
        (format "rxvt -e %s &" cmd)))
      nil)
     (t
      (apply 'eshell-exec-visual (cons "ssh" args))))))
一大堆全是括号 :shock:
PHP是最好的语言!不服来战!
zhangsong023
帖子: 768
注册时间: 2006-09-20 19:56

#36

帖子 zhangsong023 » 2007-11-18 11:54

如果习惯在终端打开文件进行编辑的,强烈地推荐一下Emacs的multi-tty功能,现在编译的CVS版本已经和mutli-tty的代码merge了,可以同时打开多个窗口连接server的,且速度其快无比,很不错。

给个图:
使用emacsclient在终端中连接server,直接在终端中打开,不必跳到server上。
图片

效果:
图片
Wang Lei
帖子: 214
注册时间: 2007-07-16 21:42

#37

帖子 Wang Lei » 2007-11-19 8:36

zhangsong023 写了:我不用sudo,对于apt,可以自己写一个函数,pcomplete/apt。
参见pcomplete/make,在pcmpl-gnu.el中。
再强调一下,要把eshell用爽一定要熟悉elisp语言。
elisp已经学习了一些,就是看那个intro,不过还没有看完呢:)
HP Compaq 6515b(GL087PA)
Sawfish+Emacs+Firefox+Xpdf+MPlayer...
Wang Lei
帖子: 214
注册时间: 2007-07-16 21:42

#38

帖子 Wang Lei » 2007-11-19 8:38

vupiggy 写了:啊,就是flymake。这个对于高手来说的确是鸡肋了。不过对于普通程序员来说真是听管事儿的。我记得我和我朋友讨论过这个问题,大致结论是如果你能一气写200行程序,一次性编译通过已经很厉害了。后来我的一个老师也说了差不多同样的话,大意是150行的程序一次性编译通过的做我的RA我非常欢迎。flymake其实是为了纠正一些低级的笔误和粗心大意造成的错误,省得当你写了1000多行以后make一次报无数的错误,然后不停地改不停地make。对于普通程序员来说还是很友好的。是有些bug,不过基本不影响使用。
既然是鸡肋还是不打算用了,省得成了习惯以后再改。

开这个贴就是为了吸取一下大家的经验,固定在一种方式后,就不再改了呵。
HP Compaq 6515b(GL087PA)
Sawfish+Emacs+Firefox+Xpdf+MPlayer...
Wang Lei
帖子: 214
注册时间: 2007-07-16 21:42

#39

帖子 Wang Lei » 2007-11-19 8:47

aof 写了:urxvt的中文显示不应该是这样的。我用的是下面的设置,好像没有你的情况。

URxvt*font: xft:Monospace:pixelsize=12,\
xft:NSimSun,\
xft:PMingLiU
试了您的这个配置确实没有那空隙了,我原来是
!Rxvt.font: xft:Courier 10 Pitch:pixelsize=14,xft:WenQuanYi Bitmap Song:antialias=false
我没有simsun,Monospace与WenQuanYi配合也可以,看来是Courier这个字体的原因,深层次原因不想深究了:)

看来这个方式也不错哈。现在看,urxvt + emacs -nw我已经挑不出毛病了:)

不过还是想看看,eshell的好处,被LS几位大侠说动心了:)

估计我把eshell配置好后,urxvt + emacs-nw的仅剩的好处,emacs没法满足的就是,背景透明了:我没法看见我设成桌面的MM,因为我一进X打开的程序全是全屏,没理由都最小化了看MM吧;)

感谢aof!
HP Compaq 6515b(GL087PA)
Sawfish+Emacs+Firefox+Xpdf+MPlayer...
Wang Lei
帖子: 214
注册时间: 2007-07-16 21:42

#40

帖子 Wang Lei » 2007-11-19 9:59

[quote="zhangsong023"]如果习惯在终端打开文件进行编辑的,强烈地推荐一下Emacs的multi-tty功能,现在编译的CVS版本已经和mutli-tty的代码merge了,可以同时打开多个窗口连接server的,且速度其快无比,很不错。

我用的是CVS版的呀,可是没有,emacsclient的-t选项,正在CVS最新镜像。

感谢LS指导啊!
HP Compaq 6515b(GL087PA)
Sawfish+Emacs+Firefox+Xpdf+MPlayer...
zhangsong023
帖子: 768
注册时间: 2006-09-20 19:56

#41

帖子 zhangsong023 » 2007-11-19 10:50

楼上的,要23.0.50以上的版本才行的。
Wang Lei
帖子: 214
注册时间: 2007-07-16 21:42

#42

帖子 Wang Lei » 2007-11-19 19:19

哦,最新下的是23.0.60。

LS的版本跟得够快呀:)
HP Compaq 6515b(GL087PA)
Sawfish+Emacs+Firefox+Xpdf+MPlayer...
zhangsong023
帖子: 768
注册时间: 2006-09-20 19:56

#43

帖子 zhangsong023 » 2007-11-19 23:16

我以前都用22的,直到我知道multi-tty merge到CVS Head以后才换的,还不久。

基本上不无聊地跟版本,浪费时间。
头像
zhan
帖子: 1880
注册时间: 2005-08-15 0:04
来自: 南7技校

#44

帖子 zhan » 2007-11-19 23:57

哈,还很热闹啊...

我现在最郁闷的是 multi-tty 开出来的 emacs 中文字体的问题。

裸的 emacs 字体定义得很漂亮了,但是 multi-tty 开的字体就貌似按照 字典序选的
为了配合 xetex 我弄了 Adobe 的几个 otf 扔到 .fonts 中了,这样每次它都用 Adobe 的,
很难看的说...
飞得高,飞得低,学习再学习,多少大秘密!
http://zhan.blog.ubuntu.org.cn
zhangsong023
帖子: 768
注册时间: 2006-09-20 19:56

#45

帖子 zhangsong023 » 2007-11-20 14:24

zhan 写了:哈,还很热闹啊...

我现在最郁闷的是 multi-tty 开出来的 emacs 中文字体的问题。

裸的 emacs 字体定义得很漂亮了,但是 multi-tty 开的字体就貌似按照 字典序选的
为了配合 xetex 我弄了 Adobe 的几个 otf 扔到 .fonts 中了,这样每次它都用 Adobe 的,
很难看的说...
我这里好像是直接使用终端字体,我的rxvt是文泉驿和DejaVu Sans Mono,在rxvt中开multi-tty就相应地使用这两个字体,如果用其它终端开,就使用其它终端中定义的字体,和Server上的字体似乎无关。

感觉这种设计很合理,否则连远程server应该会有问题。
回复