Subject: Re: bug#16405: info on non-existent node shows raw info buffer

From: Juri Linkov <[email-masked]>
Date: Fri, 10 Jan 2014 10:04:11 +0200

> (info "(emacs)Node That Does Not Exist")
>
> This dumps you in a raw, unformatted info buffer, which is not very
> friendly. I think it should format the info buffer as normal, go to the
> start, and only then return
>
> user-error: No such node or anchor: Node That Does Not Exist

AFAICS, this problem happens only when there is no *info* buffer
initially.  Otherwise, it recovers to the previously visited Info node.
So if there is no history then it could visit the Top node.

BTW, I see a similar problem with

  (info "(File That Does Not Exist)Node That Does Not Exist")

It displays an empty Info buffer.  I guess it would make sense to visit
the Dir node in this case. This patch should fix both problems:

=== modified file 'lisp/info.el'
--- lisp/info.el	2014-01-01 07:43:34 +0000
+++ lisp/info.el	2014-01-10 08:02:57 +0000
@@ -917,6 +917,8 @@ (defun Info-find-file (filename &optiona
 	  (setq filename found)
 	(if noerror
 	    (setq filename nil)
+	  (unless Info-history
+	    (Info-directory))
 	  (error "Info file %s does not exist" filename)))
       filename))))
 
@@ -1238,11 +1240,13 @@ (defun Info-find-node-2 (filename nodena
 		   (setq Info-point-loc nil))))))
     ;; If we did not finish finding the specified node,
     ;; go back to the previous one.
-    (or Info-current-node no-going-back (null Info-history)
-        (let ((hist (car Info-history)))
-          (setq Info-history (cdr Info-history))
-          (Info-find-node (nth 0 hist) (nth 1 hist) t)
-          (goto-char (nth 2 hist))))))
+    (unless (or Info-current-node no-going-back)
+      (if Info-history
+	  (let ((hist (car Info-history)))
+	    (setq Info-history (cdr Info-history))
+	    (Info-find-node (nth 0 hist) (nth 1 hist) t)
+	    (goto-char (nth 2 hist)))
+	(Info-find-node (or filename Info-current-file) "Top" t)))))
 
 ;; Cache the contents of the (virtual) dir file, once we have merged
 ;; it for the first time, so we can save time subsequently.