unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#43622: 28.0.50; [CLEANUP][PATCH] cperl-mode: Eliminate dead code
@ 2020-09-26  0:35 Harald Jörg
  2020-09-26 13:53 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 3+ messages in thread
From: Harald Jörg @ 2020-09-26  0:35 UTC (permalink / raw)
  To: 43622

[-- Attachment #1: Type: text/plain, Size: 1077 bytes --]

As recently discussed on the emacs-devel list, I'd like to eradicate
conditional code from cperl-mode where the conditionals evaluate to nil.

This is a rather large part of the cleanup, related to all that stuff
which has changed in the last years with regard to font-lock-mode and
cperl-mode's homegrown fontification based on features which are no
longer available.

I tested Perl code on my repositories (twiki.org code and
https://github.com/act-psgi/Act), written by different authors in
different styles, and could not find any change in fontification.

The conditionals leading to dead code are:

 - (featurep 'choose-color) is nil
 - (featurep 'font-lock-extra) is nil
 - (facep 'font-lock-constant-face) is t and
   (boundp 'font-lock-constant-face) is t
   ...same for other faces provided by font-lock-mode.

Once this dead code is eliminated, the macro cperl-force-face and the
function cperl-init-faces-weak (both undocumented) lose their purpose
and are also deleted.

There should be no user-visible changes, so I have made no entry in
etc/NEWS.
--
Cheers,
haj

[-- Attachment #2: 0001-cperl-mode-Delete-conditional-code-where-conditions-.patch --]
[-- Type: text/x-patch, Size: 11896 bytes --]

From e7e810675f32f43e3f2ac0ef90bc982fc5e8a787 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Harald=20J=C3=B6rg?= <haj@posteo.de>
Date: Sat, 26 Sep 2020 01:58:54 +0200
Subject: [PATCH] cperl-mode: Delete conditional code where conditions evaluate
 to nil

The features font-lock-extra and choose-color are no longer
available.  Faces defined by font-lock-mode are always
defined.  Therefore, conditional code which checks on these
is dead code and deleted.

* lisp/progmodes/cperl-mode.el (cperl-force-face): This
macro's single effect is now inlined, and the macro is gone.
(cperl-problems): The reference to choose-color.el, which
is no longer available for download, is deleted.
(no function): A list of unnecessary empty variable
definitions is gone.  They were needed for Emacs v19 and
below.
(cperl-init-faces-weak): This function does no longer do
anything and is therefore deleted.
(cperl-init-faces): Some bodies of conditional code is deleted
because as of today the conditions evaluate to constants.  The
face cperl-nonoverridable-face is no longer available as
variable and needs to be doubly-quoted in one place.
---
 lisp/progmodes/cperl-mode.el | 211 +----------------------------------
 1 file changed, 3 insertions(+), 208 deletions(-)

diff --git a/lisp/progmodes/cperl-mode.el b/lisp/progmodes/cperl-mode.el
index 468ffc949a..1e31a5fa40 100644
--- a/lisp/progmodes/cperl-mode.el
+++ b/lisp/progmodes/cperl-mode.el
@@ -82,13 +82,6 @@ gud-perldb-history
 (defvar vc-rcs-header)
 (defvar vc-sccs-header)
 
-(defmacro cperl-force-face (arg descr)  ; Takes unquoted arg
-  `(progn
-     (or (facep (quote ,arg))
-	 (make-face ,arg))
-     (or (boundp (quote ,arg))          ; We use unquoted variants too
-	 (defvar ,arg (quote ,arg) ,descr))))
-
 (defun cperl-choose-color (&rest list)
   (let (answer)
     (while list
@@ -663,10 +656,6 @@ cperl-tips
 
 (defvar cperl-problems 'please-ignore-this-line
   "Description of problems in CPerl mode.
-Some faces will not be shown on some versions of Emacs unless you
-install choose-color.el, available from
-  http://ilyaz.org/software/emacs
-
 `fill-paragraph' on a comment may leave the point behind the
 paragraph.  It also triggers a bug in some versions of Emacs (CPerl tries
 to detect it and bulk out).
@@ -3262,9 +3251,6 @@ cperl-forward-group-in-re
     result))
 
 
-(defvar font-lock-string-face)
-;;(defvar font-lock-reference-face)
-(defvar font-lock-constant-face)
 (defsubst cperl-postpone-fontification (b e type val &optional now)
   ;; Do after syntactic fontification?
   (if cperl-syntaxify-by-font-lock
@@ -3330,16 +3316,6 @@ cperl-unwind-to-safe
 			   (setq end (point)))))
 	  (or end pos)))))
 
-;; These are needed for byte-compile (at least with v19)
-(defvar cperl-nonoverridable-face)
-(defvar font-lock-variable-name-face)
-(defvar font-lock-function-name-face)
-(defvar font-lock-keyword-face)
-(defvar font-lock-builtin-face)
-(defvar font-lock-type-face)
-(defvar font-lock-comment-face)
-(defvar font-lock-warning-face)
-
 (defun cperl-find-sub-attrs (&optional st-l b-fname e-fname pos)
   "Syntactically mark (and fontify) attributes of a subroutine.
 Should be called with the point before leading colon of an attribute."
@@ -5474,17 +5450,6 @@ cperl-load-font-lock-keywords-2
   (or cperl-faces-init (cperl-init-faces))
   cperl-font-lock-keywords-2)
 
-(defun cperl-init-faces-weak ()
-  ;; Allow `cperl-find-pods-heres' to run.
-  (or (boundp 'font-lock-constant-face)
-      (cperl-force-face font-lock-constant-face
-                        "Face for constant and label names"))
-  (or (boundp 'font-lock-warning-face)
-      (cperl-force-face font-lock-warning-face
-			"Face for things which should stand out"))
-  ;;(setq font-lock-constant-face 'font-lock-constant-face)
-  )
-
 (defun cperl-init-faces ()
   (condition-case errs
       (progn
@@ -5612,7 +5577,7 @@ cperl-init-faces
 	      "wh\\(en\\|ile\\)\\|y\\|__\\(END\\|DATA\\)__" ;__DATA__ added manually
 	      "\\|[sm]"			; Added manually
 	      "\\)\\>")
-             2 'cperl-nonoverridable-face)
+	     2 ''cperl-nonoverridable-face) ; unbound as var, so: doubly quoted
 	    ;;		(mapconcat #'identity
 	    ;;			   '("#endif" "#else" "#ifdef" "#ifndef" "#if"
 	    ;;			     "#include" "#define" "#undef")
@@ -5648,11 +5613,7 @@ cperl-init-faces
 	      2 font-lock-function-name-face)
 	    '("^[ \t]*format[ \t]+\\([a-zA-Z_][a-zA-Z_0-9:]*\\)[ \t]*=[ \t]*$"
 	      1 font-lock-function-name-face)
-	    (cond ((featurep 'font-lock-extra)
-		   '("\\([]}\\%@>*&]\\|\\$[a-zA-Z0-9_:]*\\)[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
-		     (2 font-lock-string-face t)
-		     (0 '(restart 2 t)))) ; To highlight $a{bc}{ef}
-		  (font-lock-anchored
+	    (cond (font-lock-anchored
 		   '("\\([]}\\%@>*&]\\|\\$[a-zA-Z0-9_:]*\\)[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
 		     (2 font-lock-string-face t)
 		     ("\\=[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}"
@@ -5670,15 +5631,7 @@ cperl-init-faces
             ;;; '("[$*]{?\\(\\sw+\\)" 1 font-lock-variable-name-face)
             ;;; '("\\([@%]\\|\\$#\\)\\(\\sw+\\)"
             ;;;  (2 (cons font-lock-variable-name-face '(underline))))
-	    (cond ((featurep 'font-lock-extra)
-		   '("^[ \t]*\\(state\\|my\\|local\\|our\\)[ \t]*\\(([ \t]*\\)?\\([$@%*][a-zA-Z0-9_:]+\\)\\([ \t]*,\\)?"
-		     (3 font-lock-variable-name-face)
-		     (4 '(another 4 nil
-				  ("\\=[ \t]*,[ \t]*\\([$@%*][a-zA-Z0-9_:]+\\)\\([ \t]*,\\)?"
-				   (1 font-lock-variable-name-face)
-				   (2 '(restart 2 nil) nil t)))
-			nil t)))	; local variables, multiple
-		  (font-lock-anchored
+	    (cond (font-lock-anchored
 		   ;; 1=my_etc, 2=white? 3=(+white? 4=white? 5=var
 		   `(,(concat "\\<\\(state\\|my\\|local\\|our\\)"
 				  cperl-maybe-white-and-comment-rex
@@ -5780,164 +5733,6 @@ cperl-init-faces
 					   t-font-lock-keywords-1
 					   cperl-font-lock-keywords-1)))
 	(if (fboundp 'ps-print-buffer) (cperl-ps-print-init))
-	(if (or (featurep 'choose-color) (featurep 'font-lock-extra))
-	    (eval			; Avoid a warning
-	     '(font-lock-require-faces
-	       (list
-		;; Color-light    Color-dark      Gray-light      Gray-dark Mono
-		(list 'font-lock-comment-face
-		      ["Firebrick"	"OrangeRed" 	"DimGray"	"Gray80"]
-		      nil
-		      [nil		nil		t		t	t]
-		      [nil		nil		t		t	t]
-		      nil)
-		(list 'font-lock-string-face
-		      ["RosyBrown"	"LightSalmon" 	"Gray50"	"LightGray"]
-		      nil
-		      nil
-		      [nil		nil		t		t	t]
-		      nil)
-		(list 'font-lock-function-name-face
-		      (vector
-		       "Blue"		"LightSkyBlue"	"Gray50"	"LightGray"
-		       (cdr (assq 'background-color ; if mono
-				  (frame-parameters))))
-		      (vector
-		       nil		nil		nil		nil
-		       (cdr (assq 'foreground-color ; if mono
-				  (frame-parameters))))
-		      [nil		nil		t		t	t]
-		      nil
-		      nil)
-		(list 'font-lock-variable-name-face
-		      ["DarkGoldenrod"	"LightGoldenrod" "DimGray"	"Gray90"]
-		      nil
-		      [nil		nil		t		t	t]
-		      [nil		nil		t		t	t]
-		      nil)
-		(list 'font-lock-type-face
-		      ["DarkOliveGreen"	"PaleGreen" 	"DimGray"	"Gray80"]
-		      nil
-		      [nil		nil		t		t	t]
-		      nil
-		      [nil		nil		t		t	t])
-		(list 'font-lock-warning-face
-		      ["Pink"		"Red"		"Gray50"	"LightGray"]
-		      ["gray20"		"gray90"
-							"gray80"	"gray20"]
-		      [nil		nil		t		t	t]
-		      nil
-		      [nil		nil		t		t	t]
-		      )
-		(list 'font-lock-constant-face
-		      ["CadetBlue"	"Aquamarine" 	"Gray50"	"LightGray"]
-		      nil
-		      [nil		nil		t		t	t]
-		      nil
-		      [nil		nil		t		t	t])
-		(list 'cperl-nonoverridable-face
-		      ["chartreuse3"	("orchid1" "orange")
-		       nil		"Gray80"]
-		      [nil		nil		"gray90"]
-		      [nil		nil		nil		t	t]
-		      [nil		nil		t		t]
-		      [nil		nil		t		t	t])
-		(list 'cperl-array-face
-		      ["blue"		"yellow" 	nil		"Gray80"]
-		      ["lightyellow2"	("navy" "os2blue" "darkgreen")
-		       "gray90"]
-		      t
-		      nil
-		      nil)
-		(list 'cperl-hash-face
-		      ["red"		"red"	 	nil		"Gray80"]
-		      ["lightyellow2"	("navy" "os2blue" "darkgreen")
-		       "gray90"]
-		      t
-		      t
-		      nil))))
-	  ;; Do it the dull way, without choose-color
-	  (cperl-force-face font-lock-constant-face
-			    "Face for constant and label names")
-	  (cperl-force-face font-lock-variable-name-face
-			    "Face for variable names")
-	  (cperl-force-face font-lock-type-face
-			    "Face for data types")
-	  (cperl-force-face cperl-nonoverridable-face
-			    "Face for data types from another group")
-	  (cperl-force-face font-lock-warning-face
-			    "Face for things which should stand out")
-	  (cperl-force-face font-lock-comment-face
-			    "Face for comments")
-	  (cperl-force-face font-lock-function-name-face
-			    "Face for function names")
-	  ;;(defvar font-lock-constant-face 'font-lock-constant-face)
-	  ;;(defvar font-lock-variable-name-face 'font-lock-variable-name-face)
-	  ;;(or (boundp 'font-lock-type-face)
-	  ;;    (defconst font-lock-type-face
-	  ;;	'font-lock-type-face
-	  ;;	"Face to use for data types."))
-	  ;;(or (boundp 'cperl-nonoverridable-face)
-	  ;;    (defconst cperl-nonoverridable-face
-	  ;;	'cperl-nonoverridable-face
-	  ;;	"Face to use for data types from another group."))
-	  (if (and
-	       (not (facep 'cperl-array-face))
-	       (facep 'font-lock-emphasized-face))
-	      (copy-face 'font-lock-emphasized-face 'cperl-array-face))
-	  (if (and
-	       (not (facep 'cperl-hash-face))
-	       (facep 'font-lock-other-emphasized-face))
-	      (copy-face 'font-lock-other-emphasized-face 'cperl-hash-face))
-	  (if (and
-	       (not (facep 'cperl-nonoverridable-face))
-	       (facep 'font-lock-other-type-face))
-	      (copy-face 'font-lock-other-type-face 'cperl-nonoverridable-face))
-	  ;;(or (boundp 'cperl-hash-face)
-	  ;;    (defconst cperl-hash-face
-	  ;;	'cperl-hash-face
-	  ;;	"Face to use for hashes."))
-	  ;;(or (boundp 'cperl-array-face)
-	  ;;    (defconst cperl-array-face
-	  ;;	'cperl-array-face
-	  ;;	"Face to use for arrays."))
-	  (let ((background 'light))
-	    (and (not (facep 'font-lock-constant-face))
-		 (facep 'font-lock-reference-face)
-		 (copy-face 'font-lock-reference-face 'font-lock-constant-face))
-	    (if (facep 'font-lock-type-face) nil
-	      (copy-face 'default 'font-lock-type-face)
-	      (cond
-	       ((eq background 'light)
-		(set-face-foreground 'font-lock-type-face
-				     (if (x-color-defined-p "seagreen")
-					 "seagreen"
-				       "sea green")))
-	       ((eq background 'dark)
-		(set-face-foreground 'font-lock-type-face
-				     (if (x-color-defined-p "os2pink")
-					 "os2pink"
-				       "pink")))
-	       (t
-		(set-face-background 'font-lock-type-face "gray90"))))
-	    (if (facep 'cperl-nonoverridable-face)
-		nil
-	      (copy-face 'font-lock-type-face 'cperl-nonoverridable-face)
-	      (cond
-	       ((eq background 'light)
-		(set-face-foreground 'cperl-nonoverridable-face
-				     (if (x-color-defined-p "chartreuse3")
-					 "chartreuse3"
-				       "chartreuse")))
-	       ((eq background 'dark)
-		(set-face-foreground 'cperl-nonoverridable-face
-				     (if (x-color-defined-p "orchid1")
-					 "orchid1"
-				       "orange")))))
-	    (if (facep 'font-lock-variable-name-face) nil
-	      (copy-face 'italic 'font-lock-variable-name-face))
-	    (if (facep 'font-lock-constant-face) nil
-	      (copy-face 'italic 'font-lock-constant-face))))
 	(setq cperl-faces-init t))
     (error (message "cperl-init-faces (ignored): %s" errs))))
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* bug#43622: 28.0.50; [CLEANUP][PATCH] cperl-mode: Eliminate dead code
  2020-09-26  0:35 bug#43622: 28.0.50; [CLEANUP][PATCH] cperl-mode: Eliminate dead code Harald Jörg
@ 2020-09-26 13:53 ` Lars Ingebrigtsen
  2020-09-26 14:42   ` Harald Jörg
  0 siblings, 1 reply; 3+ messages in thread
From: Lars Ingebrigtsen @ 2020-09-26 13:53 UTC (permalink / raw)
  To: Harald Jörg; +Cc: 43622

Harald Jörg <haj@posteo.de> writes:

> As recently discussed on the emacs-devel list, I'd like to eradicate
> conditional code from cperl-mode where the conditionals evaluate to nil.
>
> This is a rather large part of the cleanup, related to all that stuff
> which has changed in the last years with regard to font-lock-mode and
> cperl-mode's homegrown fontification based on features which are no
> longer available.
>
> I tested Perl code on my repositories (twiki.org code and
> https://github.com/act-psgi/Act), written by different authors in
> different styles, and could not find any change in fontification.

Looks good, so I've applied it to Emacs 28 with one change:

In end of data:
progmodes/cperl-mode.el:8525:1: Warning: the function `cperl-init-faces-weak'
    is not known to be defined.

This function was removed, but the call wasn't, so I removed it (and
changed the surrounding code slightly).  If you could check that I
didn't mess up that bit, that'd be nice.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#43622: 28.0.50; [CLEANUP][PATCH] cperl-mode: Eliminate dead code
  2020-09-26 13:53 ` Lars Ingebrigtsen
@ 2020-09-26 14:42   ` Harald Jörg
  0 siblings, 0 replies; 3+ messages in thread
From: Harald Jörg @ 2020-09-26 14:42 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 43622

Lars Ingebrigtsen writes:

> Harald Jörg <haj@posteo.de> writes:
> 
>> As recently discussed on the emacs-devel list, I'd like to eradicate
>> conditional code from cperl-mode where the conditionals evaluate to nil.
>>
>> [...]
> 
> Looks good, so I've applied it to Emacs 28 with one change:
> 
> In end of data:
> progmodes/cperl-mode.el:8525:1: Warning: the function `cperl-init-faces-weak'
>     is not known to be defined.
> 
> This function was removed, but the call wasn't, so I removed it (and
> changed the surrounding code slightly).  If you could check that I
> didn't mess up that bit, that'd be nice.

Ouch - my bad.  I missed to apply that hunk.  I had a solution with the
same logic, but less elegant (closer to the original).  Many thanks for
spotting this!

-- 
Cheers,
haj





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-09-26 14:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-26  0:35 bug#43622: 28.0.50; [CLEANUP][PATCH] cperl-mode: Eliminate dead code Harald Jörg
2020-09-26 13:53 ` Lars Ingebrigtsen
2020-09-26 14:42   ` Harald Jörg

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).