* bug#46302: 28.0.50; cperl-mode cleanup: Eliminate dead code
@ 2021-02-04 19:21 Harald Jörg
2021-02-04 19:52 ` Lars Ingebrigtsen
0 siblings, 1 reply; 6+ messages in thread
From: Harald Jörg @ 2021-02-04 19:21 UTC (permalink / raw)
To: 46302
[-- Attachment #1: Type: text/plain, Size: 531 bytes --]
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
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: cperl-mode cleanup: Eliminate dead code --]
[-- Type: text/x-diff, Size: 9679 bytes --]
From cf9c369726819c1261e06a5f273c11b0a34b8576 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Harald=20J=C3=B6rg?= <haj@posteo.de>
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
^ permalink raw reply related [flat|nested] 6+ messages in thread
* bug#46302: 28.0.50; cperl-mode cleanup: Eliminate dead code
2021-02-04 19:21 bug#46302: 28.0.50; cperl-mode cleanup: Eliminate dead code Harald Jörg
@ 2021-02-04 19:52 ` Lars Ingebrigtsen
2021-02-04 22:28 ` Harald Jörg
0 siblings, 1 reply; 6+ messages in thread
From: Lars Ingebrigtsen @ 2021-02-04 19:52 UTC (permalink / raw)
To: Harald Jörg; +Cc: 46302
haj@posteo.de (Harald Jörg) writes:
> 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.
I don't get any warnings when compiling cperl-mode.el?
Anyway, the patch looks good to me, so I've applied it to Emacs 28.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 6+ messages in thread
* bug#46302: 28.0.50; cperl-mode cleanup: Eliminate dead code
2021-02-04 19:52 ` Lars Ingebrigtsen
@ 2021-02-04 22:28 ` Harald Jörg
2021-02-05 8:57 ` Lars Ingebrigtsen
0 siblings, 1 reply; 6+ messages in thread
From: Harald Jörg @ 2021-02-04 22:28 UTC (permalink / raw)
To: Lars Ingebrigtsen; +Cc: 46302
Lars Ingebrigtsen <larsi@gnus.org> writes:
> haj@posteo.de (Harald Jörg) writes:
>
>> 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.
>
> I don't get any warnings when compiling cperl-mode.el?
Ooops... Me neither.
I seem to recall a warning in the *Compile-Log* buffer that
`font-lock-syntactic.keywords' is an obsolete variable. However, I
can't reproduce it :(
Did I hallucinate? I had a look: The variable _is_ obsolete as of
font-lock.el:
(make-obsolete-variable 'font-lock-syntactic-keywords
'syntax-propertize-function "24.1")
Isn't `make-obsolete-variable` supposed to generate a compiler warning?
Or maybe I found the warning in C-h v font-lock-syntactic-keywords?
I'm confused.
> Anyway, the patch looks good to me, so I've applied it to Emacs 28.
Thanks!
--
Cheers,
haj
^ permalink raw reply [flat|nested] 6+ messages in thread
* bug#46302: 28.0.50; cperl-mode cleanup: Eliminate dead code
2021-02-04 22:28 ` Harald Jörg
@ 2021-02-05 8:57 ` Lars Ingebrigtsen
2021-02-05 10:54 ` Harald Jörg
0 siblings, 1 reply; 6+ messages in thread
From: Lars Ingebrigtsen @ 2021-02-05 8:57 UTC (permalink / raw)
To: Harald Jörg; +Cc: 46302
haj@posteo.de (Harald Jörg) writes:
> Did I hallucinate? I had a look: The variable _is_ obsolete as of
> font-lock.el:
>
> (make-obsolete-variable 'font-lock-syntactic-keywords
> 'syntax-propertize-function "24.1")
>
> Isn't `make-obsolete-variable` supposed to generate a compiler warning?
It is supposed to, but somehow it didn't... I just tried putting a
(setq-local font-lock-syntactic-keywords
(if cperl-syntaxify-by-font-lock
'((cperl-fontify-syntaxically))
into the function, and I got a
cperl-mode.el:1678:15: Warning: ‘font-lock-syntactic-keywords’ is an obsolete
variable (as of 24.1); use ‘syntax-propertize-function’ instead.
as expected.
Hm... perhaps it's because of this?
- (if cperl-use-syntax-table-text-property
- (if (eval-when-compile (fboundp 'syntax-propertize-rules))
- (progn
And the compiler got confused and didn't output a warning (always)?
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 6+ messages in thread
* bug#46302: 28.0.50; cperl-mode cleanup: Eliminate dead code
2021-02-05 8:57 ` Lars Ingebrigtsen
@ 2021-02-05 10:54 ` Harald Jörg
2021-02-05 11:03 ` Lars Ingebrigtsen
0 siblings, 1 reply; 6+ messages in thread
From: Harald Jörg @ 2021-02-05 10:54 UTC (permalink / raw)
To: Lars Ingebrigtsen; +Cc: 46302
Lars Ingebrigtsen <larsi@gnus.org> writes:
>> Isn't `make-obsolete-variable` supposed to generate a compiler warning?
>
> It is supposed to, but somehow it didn't... [...]
>
> Hm... perhaps it's because of this?
>
> - (if cperl-use-syntax-table-text-property
> - (if (eval-when-compile (fboundp 'syntax-propertize-rules))
> - (progn
>
> And the compiler got confused and didn't output a warning (always)?
Ah, that reminds me of something... I did the elimination in several
steps, and in one of them killed the conditional and the if-branch, but
forget to kill the else-branch as well. Apparently I ran the first
compilation test with that (bogus) intermediate version, and got the
warning.
As it turns out, the byte compiler shortcuts the conditional if it
eval-when-compiles to a constant and doesn't even touch the else-branch.
Digging into the commit logs reveals:
commit 4813c453b22ff7b965e31a30d35b70f73d6bcbc7
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Date: Sun Feb 3 10:47:12 2013 -0500
* lisp/progmodes/cperl-mode.el (cperl-mode): Avoid byte-compile
warning.
Now it all makes sense :)
--
Cheers,
haj
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-02-05 11:03 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-02-04 19:21 bug#46302: 28.0.50; cperl-mode cleanup: Eliminate dead code Harald Jörg
2021-02-04 19:52 ` Lars Ingebrigtsen
2021-02-04 22:28 ` Harald Jörg
2021-02-05 8:57 ` Lars Ingebrigtsen
2021-02-05 10:54 ` Harald Jörg
2021-02-05 11:03 ` Lars Ingebrigtsen
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.