Subject: Fix for failing indentation of Tcl procs nested in namespace

From: Anticrisis <[email-masked]>
Date: Thu, 21 Jan 2021 15:17:41 -1000

This patch corrects the problem by partially backing out changes
introduced in this commit 2 1/2 years ago:

https://git.savannah.gnu.org/cgit/emacs.git/commit/lisp/progmodes/tcl.el?id=cd5bb4bf3dbad8941d25823f398b595b8f0edbb9

The patch removes the customized tcl-beginning-of-defun-function in
favor of relying on the existing lisp mechanism. It preserves the
customized tcl-end-of-defun-function because that is required for some
test cases.

The expected-failing test was marked as succeeding.

This is a minor change. I did not refer to any code outside of emacs
itself in investigating and correcting this bug. I will not be able to
provide additional paperwork.
diff --git a/lisp/progmodes/tcl.el b/lisp/progmodes/tcl.el
index 0a0118a5eb..c294a2af22 100644
--- a/lisp/progmodes/tcl.el
+++ b/lisp/progmodes/tcl.el
@@ -651,7 +651,6 @@ tcl-mode
   (setq-local add-log-current-defun-function
        #'tcl-add-log-defun)
 
-  (setq-local beginning-of-defun-function #'tcl-beginning-of-defun-function)
    (setq-local end-of-defun-function #'tcl-end-of-defun-function))
 
 
@@ -849,14 +848,12 @@ tcl-calculate-indent
            state
            containing-sexp
            found-next-line)
-      (cond
-       (parse-start
+
+      (if parse-start
           (goto-char parse-start))
-       ((not (beginning-of-defun))
-        ;; If we're not in a function, don't use
-        ;; `tcl-beginning-of-defun-function'.
-        (let ((beginning-of-defun-function nil))
-          (beginning-of-defun))))
+
+      (beginning-of-defun)
+
       (while (< (point) indent-point)
         (setq parse-start (point))
         (setq state (parse-partial-sexp (point) indent-point 0))
@@ -1035,22 +1032,6 @@ tcl-indent-exp
 ;; Interfaces to other packages.
 ;;
 
-(defun tcl-beginning-of-defun-function (&optional arg)
-  "`beginning-of-defun-function' for Tcl mode."
-  (when (or (not arg) (= arg 0))
-    (setq arg 1))
-  (let* ((search-fn (if (> arg 0)
-                        ;; Positive arg means to search backward.
-                        #'re-search-backward
-                      #'re-search-forward))
-         (arg (abs arg))
-         (result t))
-    (while (and (> arg 0) result)
-      (unless (funcall search-fn tcl-proc-regexp nil t)
-        (setq result nil))
-      (setq arg (1- arg)))
-    result))
-
 (defun tcl-end-of-defun-function ()
   "`end-of-defun-function' for Tcl mode."
   ;; Because we let users redefine tcl-proc-list, we don't really know
diff --git a/test/lisp/progmodes/tcl-tests.el b/test/lisp/progmodes/tcl-tests.el
index cf1ed2896e..e55eb6d901 100644
--- a/test/lisp/progmodes/tcl-tests.el
+++ b/test/lisp/progmodes/tcl-tests.el
@@ -74,7 +74,6 @@ tcl-mode-namespace-indent
 
 ;; From bug#44834
 (ert-deftest tcl-mode-namespace-indent-2 ()
-  :expected-result :failed
   (with-temp-buffer
     (tcl-mode)
     (let ((text "namespace eval Foo {\n    proc foo {} {}\n\n    proc bar {}{}}\n"))