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

不同视角、不同观点、深度探讨,禁止人品和道德攻击
vupiggy
帖子: 89
注册时间: 2006-03-19 18:25
来自: FZ->TJ->PEK->AMS->MTL

#16

帖子 vupiggy »

Quentin 写了:vim + ctags + gcc + Makefile

这是Linux下最简单, 基本, 最强大的开发工具.
又一个说话绝对的,欢迎。

简单是简单,基本是基本,最强大嘛,呵呵,完了,这个帖子搞不好要变成经典的vi vs emacs。
就问三句:vim下可以调试程序吗?可以开terminal吗?可以做实时语法检查吗?

刚开始是vim+cscope,三年以前改用emacs+etags了,vim还是emacs倒没什么特别喜好,可能更喜欢vim一些。

BTW: 偶也用eshell ;)
zhangsong023
帖子: 768
注册时间: 2006-09-20 19:56

#17

帖子 zhangsong023 »

15楼的,别老“最”“最”的,整个一文革思维。

楼上的,“实时语法检查”,你指什么?增量编译?flymake?那个东东还是有点buggy的。
Quentin
帖子: 18
注册时间: 2007-10-15 23:45

#18

帖子 Quentin »

vupiggy 写了:
Quentin 写了:vim + ctags + gcc + Makefile

这是Linux下最简单, 基本, 最强大的开发工具.
又一个说话绝对的,欢迎。

简单是简单,基本是基本,最强大嘛,呵呵,完了,这个帖子搞不好要变成经典的vi vs emacs。
就问三句:vim下可以调试程序吗?可以开terminal吗?可以做实时语法检查吗?

刚开始是vim+cscope,三年以前改用emacs+etags了,vim还是emacs倒没什么特别喜好,可能更喜欢vim一些。

BTW: 偶也用eshell ;)
呵呵, 我妥协.
vim可不可以调程序, 开terminal, 实时语法检查, 我不知道, 还有很多功能我根本就不知道, 我最多知道了vim %10的用法, 但我已经感到非常强大, 得心应手.

或许emacs更强大, 不否认, 不过你说的这三个功能感觉是噱头, 单步调试?很少用, gdb才是王道. 开terminal? 不知道是啥功能. 实时语法检查, 适合于新手.
Quentin
帖子: 18
注册时间: 2007-10-15 23:45

#19

帖子 Quentin »

zhangsong023 写了:15楼的,别老“最”“最”的,整个一文革思维。

楼上的,“实时语法检查”,你指什么?增量编译?flymake?那个东东还是有点buggy的。
哎, 又被扣帽子了 :)
Wang Lei
帖子: 214
注册时间: 2007-07-16 21:42

#20

帖子 Wang Lei »

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

BTW,没想到这贴并不冷哈,大家好好交流呀,千万别搞成VI VS EMACS的圣战,大牛们都争论了几十年的东西,都没有结果,我等小辈还是好好学习点东西吧。等大家用到大牛的水平再争论也不迟呀。我只知道我现在连EMACS的最基本的功能都没有用到多少,包括eshell呵呵。连elisp都不会,我不会与人争论的:(
HP Compaq 6515b(GL087PA)
Sawfish+Emacs+Firefox+Xpdf+MPlayer...
zhangsong023
帖子: 768
注册时间: 2006-09-20 19:56

#21

帖子 zhangsong023 »

19楼的,感觉你在18楼发的贴就挺不错啊,比那几个“最”有内容多了,起码是在讨论实际问题。不用避讳, 我不太喜欢类似15楼的贴子。

说到调试,linux下gdb是王道没错,但vim和gdb整合太差了,有人在做这方面的工作,但还没有明显进展。Emacs就不一样,和gdb本就是一家的,整合得非常舒服的。

开terminal,就是在Emacs中使用终端模拟器,不用老是切换了,并且eshell还可以使用lisp语法,很强大的。

实时语法检查,我不知道vupiggy说的是不是flymake,这个用在类C的语言中,确实是鸡肋,但用在perl一类的东东上,还是很不错的。
zhangsong023
帖子: 768
注册时间: 2006-09-20 19:56

#22

帖子 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))))))
上次由 zhangsong023 在 2007-11-17 15:23,总共编辑 4 次。
zhangsong023
帖子: 768
注册时间: 2006-09-20 19:56

#23

帖子 zhangsong023 »

有我的配置,也有好多来自于Emacs-wiki上,经过我的小修小补,就成这样了,很久的时间累积起来的,至于里面会不会需要其它依赖,比如我在其它文件中定义的函数,记不太清了。
zhangsong023
帖子: 768
注册时间: 2006-09-20 19:56

#24

帖子 zhangsong023 »

又看了一下,没有额外需要的东西,只是如果你要用软件包查看工具的话,需要:
sudo apt-get install dlocate
Quentin
帖子: 18
注册时间: 2007-10-15 23:45

#25

帖子 Quentin »

呵呵, 一不小心闯进来了. 本来不想发帖, 但看见有人说ctags, 还好有自己用到的:)

其实我觉得像vi(m)和emacs, 应该是属于两种完全不同的风格, vi自身比较简单, 需要很多工具来结合. 而emacs一开始就很(强)大, 什么都是集成的.

emacs感觉上手要比vi快些, 我在大学时也用emacs, 工作后我的老大是个vim高手, 我也就跟着换了, 像vim/emacs这种东西, 有个高手在旁边你会学的很快:)

O.K. 你们继续讨论什么eshell之类, 我不参与了.
zhangsong023
帖子: 768
注册时间: 2006-09-20 19:56

#26

帖子 zhangsong023 »

使用eshell需要比较熟悉elisp语言,否则就算配好了用起来还是不会特别爽的。
Wang Lei
帖子: 214
注册时间: 2007-07-16 21:42

#27

帖子 Wang Lei »

猛将兄 写了:emacs要功能都配全,其他程序就都不要开了,他一个人把系统资源都占了
所以我坚决不用emacs
如果事情它都可以做了,还开其他程序干嘛?:)
HP Compaq 6515b(GL087PA)
Sawfish+Emacs+Firefox+Xpdf+MPlayer...
Wang Lei
帖子: 214
注册时间: 2007-07-16 21:42

#28

帖子 Wang Lei »

zhangsong023 写了:有我的配置,也有好多来自于Emacs-wiki上,经过我的小修小补,就成这样了,很久的时间累积起来的,至于里面会不会需要其它依赖,比如我在其它文件中定义的函数,记不太清了。
确实是够长的,我先仔细看看:)
HP Compaq 6515b(GL087PA)
Sawfish+Emacs+Firefox+Xpdf+MPlayer...
zhangsong023
帖子: 768
注册时间: 2006-09-20 19:56

#29

帖子 zhangsong023 »

楼上的,不是你说的那样子。

第一,问题的关键是:Emacs很多很多功能是以autolaod的形式加载的,也就是说,你需要的时候才会载入。功能配全,不见得就一定会特别慢的,因为,在一个侩话中,用到的功能是很有限的。

第二,Emacs很多事情是没有其它专门的程序做的好的,比如那个buggy的w3m插件就远远比不上ff、opera,用Emacs做它最擅长的就好了,试图用Emacs干所有事情的,个人觉得都有点儿自虐倾向。
Wang Lei
帖子: 214
注册时间: 2007-07-16 21:42

#30

帖子 Wang Lei »

zhangsong023
如果sodo 后加命令,如apt-get 再后面的install 不能补全了。怎么办?
HP Compaq 6515b(GL087PA)
Sawfish+Emacs+Firefox+Xpdf+MPlayer...
回复