开发者

launching emacs-gdb from the command line part 2

开发者 https://www.devze.com 2023-03-17 07:06 出处:网络
I want to launch emacs with gdb running.I\'d like to have all of the command line arguments fed in at the same time.This post:

I want to launch emacs with gdb running. I'd like to have all of the command line arguments fed in at the same time. This post: Start emacs-gdb from command line?, already solves 95% of the problem, but I have an annoying nagging follow-on to the problem. I really need to be able to pass in arguments that have spaces, something ala

edbg path/to/m开发者_JS百科yprog --firstarg "something with spaces" --secondarg 1

I've been searching on this site and on google, and I played around for a couple of hours, but I can't seem to figure this out.

Any ideas?


So, as I understand it you have this Bash function defined:

edbg() { emacs --eval "(gdb \"gdb --annotate=3 $*\")";}

and it doesn't work because any spaces in the arguments get reparsed into new word boundaries. Well, this is a common enough problem in Bash scripts that there's a special variable $@ that expands the arguments to the function differently when it's inside a double-quoted string. This gets us half-way there. The rest is just putting the quotes back around them:

edbg() {
  arglist="";
  for a in "$@"; do
    if [[ $a == ${a/ /} ]]; then
      arglist="$arglist $a";
    else
      arglist="$arglist \\\"$a\\\"";
    fi
  done;
  emacs --eval "(gdb \"gdb --annotate $arglist\")"
}

Note that this won't put quotes around args that contain tabs or newlines which would also require quotes; your $IFS may vary.

0

精彩评论

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