【问题标题】:How can I check if a server exists in Emacs Lisp如何检查 Emacs Lisp 中是否存在服务器
【发布时间】:2011-05-18 20:49:29
【问题描述】:

我正在编写一个函数来测试组织模式缓冲区中的断开链接:


    (setq urls '("http://google.com" "http://bing.com" "http://www.yahoo.com"  "http://thisdoesntexist.net"))
    (while (setq nextlink (car urls))
      (if (url-http-file-exists-p nextlink)
          (message "Link works: %s" nextlink)
        (message "Broken Link found: %s" nextlink))
      (setq urls (cdr urls)))

除非遇到不存在的 Web 服务器,否则此方法有效。然后它抛出一个 lisp 错误并打开一个 backtrace 缓冲区。

我想要的是首先测试服务器是否存在,如果存在则使用 url-http-file-exists-p 来检查特定文档。

谢谢

  • 编辑添加了适合我的解决方案。谢谢多夫!
    (while (setq nextlink (car urls))
      (condition-case nil
        (if (url-http-file-exists-p nextlink)
            (message "Link works: %s" nextlink)
          (message "Broken Link found: %s" nextlink))
        ((error) (message "Server not found: %s" nextlink)))
        (setq urls (cdr urls)))
    

【问题讨论】:

    标签: emacs elisp org-mode


    【解决方案1】:

    为什么不通过异常处理condition-case 块来捕获错误?

    【讨论】:

      猜你喜欢
      • 2010-10-30
      • 1970-01-01
      • 2010-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多