如何检查 Emacs Lisp 中是否存在服务器
我正在编写一个函数来测试组织模式缓冲区中的损坏链接:
(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 错误并打开一个回溯缓冲区。
我想要的是首先测试服务器是否存在的方法,如果存在,则使用 url-http-file-exists-p 检查特定文档。
感谢
- 编辑添加适合我的解决方案。谢谢多夫!
(while (setq nextlink (汽车网址)) (条件情况为零 (如果(url-http-文件-存在-p nextlink) (消息“链接有效:%s”nextlink) (消息“发现损坏的链接:%s”nextlink)) ((错误)(消息“找不到服务器:%s”下一个链接))) (setq url (cdr url)))
I am writing a function that tests for brokens links in an org-mode buffer:
(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)))
This works except when it encounters a non-existent web server. Then it throws a lisp error and opens up a backtrace buffer.
What I would like is way to first test if the server exists and if so then use url-http-file-exists-p to check for a specific document.
Thanks
- Edited to add solution that works for me. Thanks 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)))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么不通过异常处理
condition-case
块捕获错误呢?Why don't you just catch the error through an exception handling
condition-case
block?