Subject: bug#46302: 28.0.50; cperl-mode cleanup: Eliminate dead code

From: [email-masked] (Harald Jörg)
Date: Thu, 04 Feb 2021 20:21:46 +0100

In two places, CPerl mode checks whether `syntax-propertize-rules` is
fboundp, which is always true as of today.  The attached patch
eliminates this check and the corresponding "else"-Branches.

Also, an (undocumented) debug trace doesn't work in current Emacs
because the function `edebug-backtrace` was eliminated, so this call is
removed by the patch.

Finally, a workaround to set `font-lock-syntactic-keywords` is no longer
needed.  This eliminates a warning when compiling cperl-mode.el under
current Emacs.

-- 
Cheers,
haj
>From cf9c369726819c1261e06a5f273c11b0a34b8576 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Harald=20J=C3=B6rg?= <[email-masked]>
Date: Thu, 4 Feb 2021 20:10:03 +0100
Subject: [PATCH] ; cperl-mode: eliminate dead code

* lisp/progmodes/cperl-mode.el (cperl-update-syntaxification):
Eliminate check for `syntax-propertize-rules` (always true)
and eliminate unused first parameter.
(cperl-mode): Eliminate obsolete `font-lock-syntactic-keywords`,
Eliminate check for `syntax-propertize-rules` (always true).
(cperl-fontify-syntaxically): Eliminate call to
no-longer-existing function `edebug-backtrace`.
---
 lisp/progmodes/cperl-mode.el | 90 ++++++++++++------------------------
 1 file changed, 29 insertions(+), 61 deletions(-)

diff --git a/lisp/progmodes/cperl-mode.el b/lisp/progmodes/cperl-mode.el
index d401513646..a70e8e36c0 100644
--- a/lisp/progmodes/cperl-mode.el
+++ b/lisp/progmodes/cperl-mode.el
@@ -1157,25 +1157,25 @@ cperl-old-style
 	    (get-text-property (point-min) 'in-pod)
 	    (< (progn
 		 (and cperl-syntaxify-for-menu
-		      (cperl-update-syntaxification (point-max) (point-max)))
+		      (cperl-update-syntaxification (point-max)))
 		 (next-single-property-change (point-min) 'in-pod nil (point-max)))
 	       (point-max)))]
 	  ["Ispell HERE-DOCs" cperl-here-doc-spell
 	   (< (progn
 		(and cperl-syntaxify-for-menu
-		     (cperl-update-syntaxification (point-max) (point-max)))
+		     (cperl-update-syntaxification (point-max)))
 		(next-single-property-change (point-min) 'here-doc-group nil (point-max)))
 	      (point-max))]
 	  ["Narrow to this HERE-DOC" cperl-narrow-to-here-doc
 	   (eq 'here-doc  (progn
 		(and cperl-syntaxify-for-menu
-		     (cperl-update-syntaxification (point) (point)))
+		     (cperl-update-syntaxification (point)))
 		(get-text-property (point) 'syntax-type)))]
 	  ["Select this HERE-DOC or POD section"
 	   cperl-select-this-pod-or-here-doc
 	   (memq (progn
 		   (and cperl-syntaxify-for-menu
-			(cperl-update-syntaxification (point) (point)))
+			(cperl-update-syntaxification (point)))
 		   (get-text-property (point) 'syntax-type))
 		 '(here-doc pod))]
 	  "----"
@@ -1659,36 +1659,18 @@ cperl-mode
                 nil nil ((?_ . "w"))))
   ;; Reset syntaxification cache.
   (setq-local cperl-syntax-state nil)
-  (if cperl-use-syntax-table-text-property
-      (if (eval-when-compile (fboundp 'syntax-propertize-rules))
-          (progn
-            ;; Reset syntaxification cache.
-            (setq-local cperl-syntax-done-to nil)
-            (setq-local syntax-propertize-function
-                        (lambda (start end)
-                          (goto-char start)
-                          ;; Even if cperl-fontify-syntaxically has already gone
-                          ;; beyond `start', syntax-propertize has just removed
-                          ;; syntax-table properties between start and end, so we have
-                          ;; to re-apply them.
-                          (setq cperl-syntax-done-to start)
-                          (cperl-fontify-syntaxically end))))
-	;; Do not introduce variable if not needed, we check it!
-        (setq-local parse-sexp-lookup-properties t)
-	;; Our: just a plug for wrong font-lock
-        (setq-local font-lock-unfontify-region-function
-                    ;; not present with old Emacs
-                    #'cperl-font-lock-unfontify-region-function)
-	;; Reset syntaxification cache.
-        (setq-local cperl-syntax-done-to nil)
-        (setq-local font-lock-syntactic-keywords
-                    (if cperl-syntaxify-by-font-lock
-                        '((cperl-fontify-syntaxically))
-                      ;; unless font-lock-syntactic-keywords, font-lock (pre-22.1)
-                      ;;  used to ignore syntax-table text-properties.  (t) is a hack
-                      ;;  to make font-lock think that font-lock-syntactic-keywords
-                      ;;  are defined.
-                      '(t)))))
+  (when cperl-use-syntax-table-text-property
+    ;; Reset syntaxification cache.
+    (setq-local cperl-syntax-done-to nil)
+    (setq-local syntax-propertize-function
+                (lambda (start end)
+                  (goto-char start)
+                  ;; Even if cperl-fontify-syntaxically has already gone
+                  ;; beyond `start', syntax-propertize has just removed
+                  ;; syntax-table properties between start and end, so we have
+                  ;; to re-apply them.
+                  (setq cperl-syntax-done-to start)
+                  (cperl-fontify-syntaxically end))))
   (setq cperl-font-lock-multiline t) ; Not localized...
   (setq-local font-lock-multiline t)
   (setq-local font-lock-fontify-region-function
@@ -2405,7 +2387,7 @@ cperl-indent-command
 so that this line becomes properly indented.
 The relative indentation among the lines of the expression are preserved."
   (interactive "P")
-  (cperl-update-syntaxification (point) (point))
+  (cperl-update-syntaxification (point))
   (if whole-exp
       ;; If arg, always indent this line as Perl
       ;; and shift remaining lines of expression the same amount.
@@ -2533,7 +2515,7 @@ cperl-beginning-of-property
 
 (defun cperl-sniff-for-indent (&optional parse-data) ; was parse-start
   ;; the sniffer logic to understand what the current line MEANS.
-  (cperl-update-syntaxification (point) (point))
+  (cperl-update-syntaxification (point))
   (let ((res (get-text-property (point) 'syntax-type)))
     (save-excursion
       (cond
@@ -3025,7 +3007,7 @@ cperl-to-comment-or-eol
   ;; then looks for literal # or end-of-line.
   (let (state stop-in cpoint (lim (point-at-eol)) pr e)
     (or cperl-font-locking
-	(cperl-update-syntaxification lim lim))
+	(cperl-update-syntaxification lim))
     (beginning-of-line)
     (if (setq pr (get-text-property (point) 'syntax-type))
 	(setq e (next-single-property-change (point) 'syntax-type nil (point-max))))
@@ -4640,7 +4622,7 @@ cperl-after-expr-p
 `}' is treated \"smartly\" if it is not in the list)."
   (let ((lim (or lim (point-min)))
 	stop p)
-    (cperl-update-syntaxification (point) (point))
+    (cperl-update-syntaxification (point))
     (save-excursion
       (while (and (not stop) (> (point) lim))
 	(skip-chars-backward " \t\n\f" lim)
@@ -5027,7 +5009,7 @@ cperl-indent-region
 If `cperl-indent-region-fix-constructs', will improve spacing on
 conditional/loop constructs."
   (interactive "r")
-  (cperl-update-syntaxification end end)
+  (cperl-update-syntaxification end)
   (save-excursion
     (let (cperl-update-start cperl-update-end (h-a-c after-change-functions))
       (let ((indent-info (list nil nil nil)	; Cannot use '(), since will modify
@@ -5233,7 +5215,7 @@ cperl-imenu--create-perl-index
 	packages ends-ranges p marker is-proto
         is-pack index index1 name (end-range 0) package)
     (goto-char (point-min))
-    (cperl-update-syntaxification (point-max) (point-max))
+    (cperl-update-syntaxification (point-max))
     ;; Search for the function
     (progn ;;save-match-data
       (while (re-search-forward
@@ -8209,7 +8191,7 @@ cperl-map-pods-heres
     (or prop (setq prop 'in-pod))
     (or s (setq s (point-min)))
     (or end (setq end (point-max)))
-    (cperl-update-syntaxification end end)
+    (cperl-update-syntaxification end)
     (save-excursion
       (goto-char (setq pos s))
       (while (and cont (< pos end))
@@ -8225,7 +8207,7 @@ cperl-get-here-doc-region
 Return nil if the point is not in a HERE document region.  If POD is non-nil,
 will return a POD section if point is in a POD section."
   (or pos (setq pos (point)))
-  (cperl-update-syntaxification pos pos)
+  (cperl-update-syntaxification pos)
   (if (or (eq 'here-doc  (get-text-property pos 'syntax-type))
 	  (and pod
 	       (eq 'pod (get-text-property pos 'syntax-type))))
@@ -8295,7 +8277,7 @@ cperl-time-fontification
       (forward-line step)
       (setq l (+ l step))
       (setq c (1+ c))
-      (cperl-update-syntaxification (point) (point))
+      (cperl-update-syntaxification (point))
       (setq delta (- (- tt (setq tt (funcall timems)))) tot (+ tot delta))
       (message "to %s:%6s,%7s" l delta tot))
     tot))
@@ -8405,19 +8387,12 @@ cperl-font-lock-fontify-region-function
     (setq end (point)))
   (font-lock-default-fontify-region beg end loudly))
 
-(defvar cperl-d-l nil)
-(defvar edebug-backtrace-buffer)        ;FIXME: Why?
 (defun cperl-fontify-syntaxically (end)
   ;; Some vars for debugging only
   ;; (message "Syntaxifying...")
   (let ((dbg (point)) (iend end) (idone cperl-syntax-done-to)
 	(istate (car cperl-syntax-state))
-	start from-start edebug-backtrace-buffer)
-    (if (eq cperl-syntaxify-by-font-lock 'backtrace)
-	(progn
-	  (require 'edebug)
-	  (let ((f 'edebug-backtrace))
-	    (funcall f))))	; Avoid compile-time warning
+	start from-start)
     (or cperl-syntax-done-to
 	(setq cperl-syntax-done-to (point-min)
 	      from-start t))
@@ -8473,16 +8448,9 @@ cperl-after-change-function
   (if cperl-syntax-done-to
       (setq cperl-syntax-done-to (min cperl-syntax-done-to beg))))
 
-(defun cperl-update-syntaxification (from to)
-  (cond
-   ((not cperl-use-syntax-table-text-property) nil)
-   ((fboundp 'syntax-propertize) (syntax-propertize to))
-   ((and cperl-syntaxify-by-font-lock
-         (or (null cperl-syntax-done-to)
-             (< cperl-syntax-done-to to)))
-    (save-excursion
-      (goto-char from)
-      (cperl-fontify-syntaxically to)))))
+(defun cperl-update-syntaxification (to)
+  (when cperl-use-syntax-table-text-property
+    (syntax-propertize to)))
 
 (defvar cperl-version
   (let ((v  "Revision: 6.2"))
-- 
2.20.1