 ;; chosen to keep it since it provides a very useful functionality
 ;; which is not possible to achieve using a clean approach.
 ;;   / AndersL
+;;
+;; The previous hack seems to have broken in Emacs 25. This is fixed
+;; by trying to find the function in the man buffer a few times with a
+;; delay in between (see function
+;; erlang-man-repeated-search-for-function). This fix is also a hack
+;; but it should be quite robust and will work even if the function
+;; that erlang-man-function-display-man-page tries to hook into
+;; disappears or changes.
 
 (defvar erlang-man-function-name nil
   "Name of function for last `erlang-man-function' call.

          (t
           (erlang-man-module modname)
           (when funcname
             (erlang-man-find-function (current-buffer) funcname))))))

(defun erlang-man-function (&optional name)
  "Find manual page for NAME, where NAME is module:function.

    (if name
        (erlang-man-function name)
      (error "No function name under the cursor"))))

(defun erlang-man-repeated-search-for-function (man-buffer
                                                function-name
                                                &optional
                                                module-name)
  "This function tries to scroll MAN-BUFFER to the documentation
of function FUNCTION-NAME. The function will try again a few
times if the documentation for FUNCTION-NAME can't be found. This
is necessary as the man page is loaded asynchronously from Emacs
19 and the correct function to hook into depends on the Emacs
version. The function will automatically try to find the correct
buffer from the list of opened buffers if MAN-BUFFER is nil. The
optional parameter MODULE-NAME will make the search for the
buffer more accurate."
  (let* ((time-between-attempts 0.5)
         (max-wait-time 5.1)
         (search-for-function
          (lambda (self
                   time-waited
                   time-between-attempts
                   max-wait-time
                   man-buffer
                   function-name
                   module-name
                   )
            (when (and (not (erlang-man-find-function man-buffer function-name module-name))
                       (<= (+ time-waited time-between-attempts)
                           max-wait-time))
              (message "Finding function %s..." function-name)
                                        ; Call this function again later
              (run-at-time time-between-attempts nil
                           self
                           self
                           (+ time-waited time-between-attempts)
                           time-between-attempts
                           max-wait-time
                           man-buffer
                           function-name
                           module-name)
              ))))
    (funcall search-for-function
             search-for-function
             0.0
             time-between-attempts
             max-wait-time
             man-buffer
             function-name
             module-name)))

;; Should the defadvice be at the top level, the package `advice' would
;; be required.  Now it is only required when this functionality
