
(defun not-ok--d-speedbar--goto-method ()
  (interactive)
  (save-match-data
    (let (name args old-point done old-buf new-buf old-win
               new-win count str class start end
               (d-message-on t))
      (d-speedbar--turn-off-timers)
      (when (string= (buffer-name (current-buffer)) d-speedbar--buf-name)
        (unwind-protect
            (progn
              ;;(setq new-buf (get-buffer d-speedbar--buf-name))
              (setq old-buf (d-speedbar--get-old-buffer))
              ;;(setq old-buf (save-window-excursion
              ;;                (save-excursion
              ;;                  ;;(select-window d-window-right)
              ;;                  (set-buffer d-speedbar--buf-name)
              ;;                  (other-window 1)
              ;;                  (current-buffer))))
              ;;(debug 123)
              ;;(debug "old-buf=%s" old-buf)
              ;;(setq new-win (get-buffer-window new-buf))
              ;;(setq old-win (get-buffer-window old-buf))
              ;;(message "new-win=%s" new-win)
              ;;(message "old-win=%s" old-win)
              ;;(set-window-buffer new-win new-buf)
              (set-buffer d-speedbar--buf-name)
              (read-only-mode -1)
              ;;(setq p3 -1)
              (cond
               ;; ----------------------------------------------------
               ((eq d-old-major-mode 'dired-mode)
                (setq f (d-current-line-as-string))
                (find-file f))
               ;; ----------------------------------------------------
               ((eq d-old-major-mode 'java-mode)
                ;;(setq pair (d-get-class))
                ;;(setq class (if (consp pair) (car pair) nil))
                (beginning-of-line)
                (if (looking-at "^class \\([A-Za-z0-9_]+\\)$")
                    (save-excursion
                      (setq class (buffer-substring-no-properties (match-beginning 1) (match-end 1)))
                      (other-window 1)
                      (goto-char (point-min))
                      (if (not (re-search-forward (concat "^\\(public +\\|abstract +\\|final +\\)*class " class) nil t))
                          (error "smeg 7"))
                      (beginning-of-line)
                      (other-window 1)
                      )
                  (save-excursion
                    (beginning-of-line)
                    (re-search-backward "^class \\([A-Za-z0-9_]+\\)$" nil t)
                    (setq class (buffer-substring-no-properties (match-beginning 1) (match-end 1)))
                    ;;(d-beeps "class=%s" class)
                    )
                  (beginning-of-line)
                  (assert (looking-at "\\(^[A-Za-z_][A-Za-z0-9_]*\\)[ \t]*\\(([^()]*);?\\)"))
                  (setq name (if (and (match-beginning 1) (match-end 1))
                                 (buffer-substring-no-properties (match-beginning 1) (match-end 1))))
                  (setq args (if (and (match-beginning 2) (match-end 2))
                                 (buffer-substring-no-properties (match-beginning 2) (match-end 2))))
                  (debug "wrench")
                  (other-window 1)
                  (goto-char (point-min))
                  (if (not (re-search-forward (concat "^\\(public +\\|abstract +\\|final +\\)*class " class) nil t))
                      (error "smeg 8"))
                  (setq start (point))
                  (beginning-of-line)
                  (forward-line 1)
                  (assert (looking-at (concat "^{")))
                  (forward-sexp 1)
                  (setq end (point))
                  (goto-char start)
                  (debug "Carrot")
                  (while (and (re-search-forward (concat name "[ \t]*" (regexp-quote args)) end t)
                              (not (save-match-data
                                     (save-excursion
                                       (forward-line 1)
                                       (beginning-of-line)
                                       (looking-at (concat "^" (make-string c-basic-offset ? ) "{")))))))
                  (beginning-of-line)
                  ;;(debug "viagra")
                  ;;(setq p3 (point))
                  ))
               ;; ----------------------------------------------------
               ((or (eq d-old-major-mode 'c-mode) (eq d-old-major-mode 'c++-mode))
                (beginning-of-line)
                (assert (looking-at "\\(^[a-zA-Z0-9_+:-]*\\)[ \t]*\\(([^()]*)\\)"))
                (setq name (buffer-substring-no-properties (match-beginning 1) (match-end 1)))
                (setq args (buffer-substring-no-properties (match-beginning 2) (match-end 2)))
                (set-buffer old-buf)
                (goto-char (point-min))
                (while (and (re-search-forward (concat name "[ \t]*" (regexp-quote args)) nil t)
                            (not (save-match-data
                                   (save-excursion
                                     (forward-line 1)
                                     (beginning-of-line)
                                     (looking-at "^   {"))))))
                (beginning-of-line)
                ;;(setq p3 (point))
                )
               ;; ----------------------------------------------------
               ((eq d-old-major-mode 'emacs-lisp-mode)
                (progn
                  (beginning-of-line)
                  (assert (looking-at "\\(^[a-zA-Z0-9_+:<>/=-]*\\)[ \t]*\\(([^()]*)\\)"))
                  (setq name (buffer-substring-no-properties (match-beginning 1) (match-end 1)))
                  (setq args (buffer-substring-no-properties (match-beginning 2) (match-end 2)))
                  (set-buffer old-buf)
                  (goto-char (point-min))
                  ;;(setq p3 -3)
                  (if (not (re-search-forward (concat name "[ \t]*" (regexp-quote args)) nil t))
                      (error "smeg 9"))
                  (beginning-of-line)
                  ;;(setq p3 (point))
                  )
                )
               ;; ------------------------------------------------------
               ((eq d-old-major-mode 'compilation-mode)
                (beginning-of-line)
                (when (looking-at "^\\*\\*\\*\\* STROBE=\"[a-zA-Z0-9]*\"")
                  (progn ;;let (list ptr line f)
                    (setq list (d-speedbar--get-compilation-strobes))
                    (setq line (concat "^[ \t]*" (regexp-quote (d-trim-string (d-current-line-as-string)))))
                    (set-buffer old-buf)
                    (message "current-buffer=%s" (current-buffer))
                    ;;(beep)
                    ;;(sit-for 5)
                    (goto-char (point-min))
                    (setq ptr list)
                    (while ptr
                      (setq f (concat "^[ \t]*" (car ptr)))
                      (if (re-search-forward f)
                          (progn
                            (message "found forward %s" f)
                            ;;(beep)
                            ;;(sit-for 1)
                            ;;(forward-char 1)
                            )
                        (message "not found forward %s" f)
                        ;;(beep)
                        ;;(sit-for 1)
                        )
                      (recenter)
                      (setq ptr (cdr ptr)))
                    (forward-char -1)
                    (if (not (re-search-forward line nil t))
                        (error "smeg 10"))
                    (goto-line 10000)
                    (beginning-of-line)
                    (recenter)
                    )))
               ;; ----------------------------------------------------
               ((eq d-old-major-mode 'php-mode)
                (beginning-of-line)
                (setq line (d-current-line-as-string))
                (other-window 1)
                (goto-char (point-min))
                (if (not (re-search-forward (concat "^[ \t]*function[ \t]*" (regexp-quote line)) nil t))
                    (error "smeg 11"))
                ;;(message "line=%s" (regexp-quote line))
                ;;(beep)
                ;; ;;(setq d-message-on t)
                ;;(message "* Pressed enter on php-mode speedbar")
                ;;(debug "banana line=%s" line)
                (beginning-of-line)
                ;;(setq p3 (point))
                )
               ;; ------------------------------------------------------
               ))
          (progn
            (switch-to-buffer d-speedbar--buf-name)
            (read-only-mode 1)
            (recenter)
            (other-window 1)
            (beginning-of-line)
            (d-speedbar--turn-on-timers)
            ;;(and 3.141 (goto-char p3))
            ))))))

(d-quote
 (let* ((frame (selected-frame))
         (list  (window-list frame))
         (ptr   list)
         (b     nil))
    (while ptr
      (setq b (progn
                (select-window (car ptr))
                (buffer-name   (current-buffer))))
      (if (and b (buffer-file-name (get-buffer b)))
          (setq ptr nil))
      (setq ptr (cdr ptr)))
    b))

(d-quote (not (and (save-excursion
                      (re-search-forward "{" (point-at-eol) t))
                         (save-match-data
                            (save-excursion
                               (forward-line 1)
                               (beginning-of-line)
                               (looking-at (concat "^" (make-string c-basic-offset ? ) "{")))))))

;;; (setq frame (selected-frame))
;;; (setq list  (window-list frame))

(defun d-speedbar--get-old-window ()
  (let (win)
    (setq win (selected-window))
    (when (string-match d-speedbar--regexp-name (buffer-name (window-buffer win)))
        (setq win (progn
                    (other-window 1)
                    (selected-window))))
    win))

