【问题标题】:Elisp: Searching for a string with an unbalanced quote causes Lisp errorElisp:搜索带有不平衡引号的字符串会导致 Lisp 错误
【发布时间】:2010-08-09 09:03:22
【问题描述】:

搜索filename . "myfile.txt"

(regexp-quote "filename \. \"\\(.+\\)\"")
"filename \\. \"\\\\(\\.\\+\\\\)\""

搜索filename . "myfile.txt(不带最后引号)

(regexp-quote "filename \. \"\\(.+\\)")
Debugger entered--Lisp error: (invalid-read-syntax ") or . in a vector")
  read(#<buffer processing-files.el>)
  preceding-sexp()
  eval-last-sexp-1(t)
  eval-last-sexp(t)
  eval-print-last-sexp()
  call-interactively(eval-print-last-sexp nil nil)

【问题讨论】:

  • 这是另一个简单的失败示例
     (re-search-forward "\"" (point-max) t) 调试器进入--Lisp 错误: (scan-error "Unbalanced parentheses" 2308 1) scan-sexps(2309 -1) forward-sexp(-1) previous-sexp() eval-last-sexp-1(nil) eval-last-sexp(nil) 交互式调用(eval-last-sexp nil nil) 
    我在 LENNART-69DE564 Windows 7 Ultimate 上使用 2010-08-04 的 GNU Emacs 24.0.50.1 (i386-mingw-nt6.1.7600)
  • 在没有我的个人配置文件的情况下加载 emacs 时不会出现此问题
  • 只需注释掉配置文件的不同部分,直到缩小范围。
  • 呃,有什么问题吗?只需运行这两个 sn-ps 即可,因此需要更多信息。

标签: regex elisp


【解决方案1】:

我认为您误解了 regexp-quote 的含义:

来自文档(C-h C-f regexp-quote RET)

返回一个与字符串完全匹配的正则表达式字符串。

或者我误解了你的问题。

无论如何,如果你想搜索,有一些函数search-backward-regexp,search-forward-regexp

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-07-19
    • 2018-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-06
    • 2016-05-18
    • 1970-01-01
    相关资源
    最近更新 更多