Open an Emacs buffer when a command tries to open an editor in shell-mode

后端 未结 6 1677
梦毁少年i
梦毁少年i 2021-02-07 04:13

I like to use Emacs\' shell mode, but it has a few deficiencies. One of those is that it\'s not smart enough to open a new buffer when a shell command tries to invoke an editor.

6条回答
  •  滥情空心
    2021-02-07 04:34

    Along with using emacs client/server, I am using this script to invoke emacs.

    This will start emacs if it is not running yet, or just open a new emacs buffer in the running emacs (using gnuclient). It runs in the background by default, but can be run in the foreground for processes that expect some input. For example, I am using this as my source control editor, when entering a change list description. I have "SVN_EDITOR=emacs sync", so I can do "svn commit" in an emacs shell, and it will open the svn editor in a new emacs buffer in the same emacs. When I close the buffer, "svn commit" continues. Pretty useful.

    #!/bin/sh
    
    if [ -z $EMACS_CMD ]; then
      EMACS_CMD="/usr/bin/emacs"
    fi
    
    if [ -z $GNUCLIENT_CMD ]; then
      GNUCLIENT_CMD="/usr/bin/gnuclient"
    fi
    
    if [ "$1" = "sync" ]; then
        shift 1
        sync=true
    else
        sync=false
    fi
    
    cmd="${EMACS_CMD} $*"
    lsof $EMACS_CMD | grep $USER >/dev/null 2>&1
    if [ "$?" -ne "1" ]; then
        cmd="${GNUCLIENT_CMD} $*"
    fi
    
    if [ $sync = "true" ]; then
        $cmd
    else
        $cmd &
    fi
    
    

提交回复
热议问题