小编Bar*_*ntz的帖子

如何检查Emacs Lisp中是否存在服务器

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


    (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)))
Run Code Online (Sandbox Code Playgroud)

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

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

谢谢

  • 编辑添加适合我的解决方案.谢谢Dov!
    (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

3
推荐指数
1
解决办法
328
查看次数

标签 统计

elisp ×1

emacs ×1

org-mode ×1