[ELPA] Update package: psgml

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[ELPA] Update package: psgml

Lucien Pullen
Update how PSGML uses `sgml-set-face' to include a list of major modes.
If the current major mode isn't in the list, treat as nil, otherwise t.

This allows PSGML's parser to be used in other major modes without
clobbering font locking in the process.


From c3cf6728d7f4bb1836aefaa78c8eb3e74f722085 Mon Sep 17 00:00:00 2001
From: Lucien Pullen <[hidden email]>
Date: Sun, 16 Apr 2017 16:00:23 -0600
Subject: [PATCH] psgml: conditionally set face from major mode

* psgml-parse.el (sgml-set-face): In addition to never (nil) and
always (t), can be a list of major mode functions to only set face in
those modes.
---
 psgml-parse.el | 12 +++++++-----
 psgml.el       |  4 +++-
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/psgml-parse.el b/psgml-parse.el
index 5609767..eb9828e 100644
--- a/psgml-parse.el
+++ b/psgml-parse.el
@@ -1317,8 +1317,9 @@ was successful or nil if failed."
   "Set the type of the markup parsed to TYPE.
 The markup starts at position given by variable `sgml-markup-start' and
 ends at point."
-  (when (and sgml-set-face
-     (null sgml-current-eref))
+  (when (and (or (eq sgml-set-face t)
+                 (find major-mode sgml-set-face))
+             (null sgml-current-eref))
     (sgml-set-face-for sgml-markup-start (point) type))
   (setq sgml-markup-type type))
 
@@ -2821,7 +2822,7 @@ overrides the entity type in entity look up."
     (when (and (not executing-macro)
        (or (and (boundp 'which-function-mode)
                         which-function-mode )
-   sgml-set-face)
+   (or (eq sgml-set-face t) (find major-mode sgml-set-face))
        sgml-buffer-parse-state
        (sit-for 0))
       (let ((deactivate-mark nil))
@@ -2833,7 +2834,8 @@ overrides the entity type in entity look up."
                   (sgml-element-gi sgml-last-element)))
  (let ((eol-pos (save-excursion (end-of-line 1) (point))))
           ;; Set face on current line
-          (when (and sgml-set-face (not (input-pending-p)))
+          (when (and (or (eq sgml-set-face t) (find major-mode sgml-set-face))
+                     (not (input-pending-p)))
             (save-excursion
               (condition-case nil
                   (sgml-parse-to
@@ -2846,7 +2848,7 @@ overrides the entity type in entity look up."
 
 (defun sgml-fontify-buffer (delay)
   (and
-   sgml-set-face
+   (or (eq sgml-set-face t) (find major-mode sgml-set-face))
    (null (sgml-tree-etag-epos
   (sgml-pstate-top-tree sgml-buffer-parse-state)))
    (sit-for delay)
diff --git a/psgml.el b/psgml.el
index 142079a..b0ff140 100644
--- a/psgml.el
+++ b/psgml.el
@@ -849,7 +849,9 @@ sgml-normalize-trims  If non-nil, sgml-normalize will trim off white space
  from end of element when adding end tag.
 sgml-indent-step  How much to increment indent for every element level.
 sgml-indent-data  If non-nil, indent in data/mixed context also.
-sgml-set-face     If non-nil, psgml will set the face of parsed markup.
+sgml-set-face     If non-nil, psgml will set the face of parsed markup,
+ either always (when t) or when the buffer's major mode matches
+ one of the listed function names.
 sgml-markup-faces The faces used when the above variable is non-nil.
 sgml-public-map  Mapping from public identifiers to file names.
 sgml-offer-save  If non-nil, ask about saving modified buffers before
--
2.3.4

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [ELPA] Update package: psgml

Stefan Monnier
> Update how PSGML uses `sgml-set-face' to include a list of major modes.
> If the current major mode isn't in the list, treat as nil, otherwise t.

> This allows PSGML's parser to be used in other major modes without
> clobbering font locking in the process.

Hmm.. I like the goal, but I don't like lists of major-modes.
Could you give some further details about the context where you bumped
into the problem?

Any reason why you couldn't set sgml-set-face to nil buffer-locally instead?


        Stefan


> From c3cf6728d7f4bb1836aefaa78c8eb3e74f722085 Mon Sep 17 00:00:00 2001
> From: Lucien Pullen <[hidden email]>
> Date: Sun, 16 Apr 2017 16:00:23 -0600
> Subject: [PATCH] psgml: conditionally set face from major mode

> * psgml-parse.el (sgml-set-face): In addition to never (nil) and
> always (t), can be a list of major mode functions to only set face in
> those modes.
> ---
>  psgml-parse.el | 12 +++++++-----
>  psgml.el       |  4 +++-
>  2 files changed, 10 insertions(+), 6 deletions(-)

> diff --git a/psgml-parse.el b/psgml-parse.el
> index 5609767..eb9828e 100644
> --- a/psgml-parse.el
> +++ b/psgml-parse.el
> @@ -1317,8 +1317,9 @@ was successful or nil if failed."
>    "Set the type of the markup parsed to TYPE.
>  The markup starts at position given by variable `sgml-markup-start' and
>  ends at point."
> -  (when (and sgml-set-face
> -     (null sgml-current-eref))
> +  (when (and (or (eq sgml-set-face t)
> +                 (find major-mode sgml-set-face))
> +             (null sgml-current-eref))
>      (sgml-set-face-for sgml-markup-start (point) type))
>    (setq sgml-markup-type type))
 

> @@ -2821,7 +2822,7 @@ overrides the entity type in entity look up."
>      (when (and (not executing-macro)
>         (or (and (boundp 'which-function-mode)
>                          which-function-mode )
> -   sgml-set-face)
> +   (or (eq sgml-set-face t) (find major-mode sgml-set-face))
>         sgml-buffer-parse-state
>         (sit-for 0))
>        (let ((deactivate-mark nil))
> @@ -2833,7 +2834,8 @@ overrides the entity type in entity look up."
>                    (sgml-element-gi sgml-last-element)))
>   (let ((eol-pos (save-excursion (end-of-line 1) (point))))
>            ;; Set face on current line
> -          (when (and sgml-set-face (not (input-pending-p)))
> +          (when (and (or (eq sgml-set-face t) (find major-mode sgml-set-face))
> +                     (not (input-pending-p)))
>              (save-excursion
>                (condition-case nil
>                    (sgml-parse-to
> @@ -2846,7 +2848,7 @@ overrides the entity type in entity look up."
 

>  (defun sgml-fontify-buffer (delay)
>    (and
> -   sgml-set-face
> +   (or (eq sgml-set-face t) (find major-mode sgml-set-face))
>     (null (sgml-tree-etag-epos
>    (sgml-pstate-top-tree sgml-buffer-parse-state)))
>     (sit-for delay)
> diff --git a/psgml.el b/psgml.el
> index 142079a..b0ff140 100644
> --- a/psgml.el
> +++ b/psgml.el
> @@ -849,7 +849,9 @@ sgml-normalize-trims  If non-nil, sgml-normalize will trim off white space
>   from end of element when adding end tag.
>  sgml-indent-step  How much to increment indent for every element level.
>  sgml-indent-data  If non-nil, indent in data/mixed context also.
> -sgml-set-face     If non-nil, psgml will set the face of parsed markup.
> +sgml-set-face     If non-nil, psgml will set the face of parsed markup,
> + either always (when t) or when the buffer's major mode matches
> + one of the listed function names.
>  sgml-markup-faces The faces used when the above variable is non-nil.
>  sgml-public-map  Mapping from public identifiers to file names.
>  sgml-offer-save  If non-nil, ask about saving modified buffers before
> --
> 2.3.4



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [ELPA] Update package: psgml

Lucien Pullen
Also sprach Stefan Monnier on 2017-04-17:
> Could you give some further details about the context where you bumped
> into the problem?

I'm doing a lot of DSSSL at the moment, and I wanted the SGML editor
commands to work in DSSSL mode.  With sgml-set-face turned on for
editing SGML structure, doing something like sgml-insert-element
fontifies for SGML up to point instead of fontifying for lisp because
PSGML fontifies as it parses the buffer to figure out the current
element.

> Hmm.. I like the goal, but I don't like lists of major-modes.
>
> Any reason why you couldn't set sgml-set-face to nil buffer-locally instead?

I actually wanted it to be mode-local, which emacs doesn't really do,
hence the list of major modes.  When in an SGML mode for editing markup,
I want the SGML to be fontified; when in some other mode for editing
notation data, I want that major mode's font locking to take place.

I can set sgml-set-face in a hook for sgml-mode, but then I have to
unset it if I want to edit in the other mode.  I figured a single list
of modes where SGML should be fontified would be easier to keep track of
than a slue of mode hooks.

I looked into indirect buffers, but this seems more intuitive.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [ELPA] Update package: psgml

Stefan Monnier
>> Could you give some further details about the context where you bumped
>> into the problem?
> I'm doing a lot of DSSSL at the moment, and I wanted the SGML editor
> commands to work in DSSSL mode.  With sgml-set-face turned on for
> editing SGML structure, doing something like sgml-insert-element
> fontifies for SGML up to point instead of fontifying for lisp because
> PSGML fontifies as it parses the buffer to figure out the current
> element.

I'm not really familiar with DSSSL, so I'm not sure what thie use case
looks like concretely.  Is that some Lisp-ish sublanguage that appears
between two SGML tags or on the contrary Lisp-ish language with SGML
tags within it (i.e. some sort of multi-major-mode situation)?

Do you use a dsssl-mode major mode for it?  Can you point me to it?

> I actually wanted it to be mode-local, which emacs doesn't really do,

Emacs does support "mode-local" in the following sense:

    (add-hook 'foo1-mode-hook (lambda () (setq-local VAR VAL1)))
    (add-hook 'foo2-mode-hook (lambda () (setq-local VAR VAL2)))
    ...

> I can set sgml-set-face in a hook for sgml-mode, but then I have to
> unset it if I want to edit in the other mode.  I figured a single list
> of modes where SGML should be fontified would be easier to keep track of
> than a slue of mode hooks.

A bunch of mode hooks is the "standard" way to deal with such situations
in Emacs.  Which is more convenient depends on the situation, admittedly.

In the specific case of psgml, I think the real fix should be to make
psgml interact more normally with font-lock.  I haven't looked into it
hard enough yet, tho.

> I looked into indirect buffers, but this seems more intuitive.

This makes me feel like you indeed have a multi-major-mode situation, in
which case sgml-set-face is probably just one part of the problem (and
using indirect buffers would just add more problems).


        Stefan


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [ELPA] Update package: psgml (discard patch)

Lucien Pullen
Also sprach Stefan Monnier on 2017-04-19:
> I'm not really familiar with DSSSL, so I'm not sure what thie use case
> looks like concretely.  Is that some Lisp-ish sublanguage that appears
> between two SGML tags or on the contrary Lisp-ish language with SGML
> tags within it (i.e. some sort of multi-major-mode situation)?
>
> Do you use a dsssl-mode major mode for it?  Can you point me to it?

It's lisp and entity references between two SGML tags, like this:

  <style-specification>
  (element par (make paragraph start-indent: &indentS;))
  </style-specification>

The mode is dsssl-mode from the built-in scheme elisp library.

>> I actually wanted it to be mode-local, which emacs doesn't really do,
>
> Emacs does support "mode-local" in the following sense:
>
>     (add-hook 'foo1-mode-hook (lambda () (setq-local VAR VAL1)))
>     (add-hook 'foo2-mode-hook (lambda () (setq-local VAR VAL2)))
>     ...

>> I can set sgml-set-face in a hook for sgml-mode, but then I have to
>> unset it if I want to edit in the other mode.  I figured a single list
>> of modes where SGML should be fontified would be easier to keep track of
>> than a slue of mode hooks.
>
> A bunch of mode hooks is the "standard" way to deal with such situations
> in Emacs.  Which is more convenient depends on the situation, admittedly.

I read the buffer local sections in the manual again following your
example.  Emacs does do mode local.  That... isn't how I understood
buffer-local variables to work.

In this case, I consider the patch unnecessary.

> In the specific case of psgml, I think the real fix should be to make
> psgml interact more normally with font-lock.  I haven't looked into it
> hard enough yet, tho.

PSGML only understands the reference concrete syntax, so, with a few
exceptions such as for fontifying Null End Tags only when they can occur
and using the value of parameter entities for marked sections, it should
be able to use font lock using regular expressions.

> This makes me feel like you indeed have a multi-major-mode situation, in
> which case sgml-set-face is probably just one part of the problem (and
> using indirect buffers would just add more problems).

I've run into multi-major-mode a lot while doing SGML stuff.  I do miss
MuMaMo integration with nHTML, but I hardly write directly in HTML any
more and I don't use PHP, so...  There's something about the NOTATION
attribute giving the editor access to which major mode element content
is in that lends itself to multi-major-mode.

At least, that's how I'd like to use psgml, but I need to learn a lot
more about modes before I tried something like making emacs SGML-aware.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [ELPA] Update package: psgml (discard patch)

Stefan Monnier
>> Do you use a dsssl-mode major mode for it?  Can you point me to it?
> It's lisp and entity references between two SGML tags, like this:
>   <style-specification>
>   (element par (make paragraph start-indent: &indentS;))
>   </style-specification>

Thanks.

> The mode is dsssl-mode from the built-in scheme elisp library.

Duh!

[ After so many years using, contributing, and maintaining Emacs,
  I still bump into "unknown" packages and major modes bundled with
  Emacs several times a year (I suspect that some of those "unknown" are
  really that I forgot about them since last time I bumped into them,
  but still).  ]

>> In the specific case of psgml, I think the real fix should be to make
>> psgml interact more normally with font-lock.  I haven't looked into it
>> hard enough yet, tho.
> PSGML only understands the reference concrete syntax, so, with a few
> exceptions such as for fontifying Null End Tags only when they can occur
> and using the value of parameter entities for marked sections, it should
> be able to use font lock using regular expressions.

From a cursory look at how it currently works, I got the impression that
it can be made to use font-lock without changing fundamentally how it's
done.  Using regexps would probably be more painful, less efficient,
and/or less reliable (luckily, font-lock is not limited to regexps).

>> This makes me feel like you indeed have a multi-major-mode situation, in
>> which case sgml-set-face is probably just one part of the problem (and
>> using indirect buffers would just add more problems).
> I've run into multi-major-mode a lot while doing SGML stuff.

[ Side note: given the goal of SGML/XML to provide a kind of "universal
  syntax", the frequency with which even things specifically designed
  for XML/SGML end up using a completely different syntax (e.g. CSS,
  RNC, DSSSL, etc...), seems to be a strong indication of failure.
  Of course, that's just the opinion of someone who's never much liked
  the SGML/XML tags because of their verbosity.  ]

> I do miss MuMaMo integration with nHTML,

Did MuMaMo disappear?

BTW, Tom Tromey has recently added a new mhtml-mode to Emacs, which
"simply" combines Emacs's html-mode js-mode and css-mode.  It won't
directly help your dsssl-mode, but maybe you could try to see if his
approach could be used for your SGML+DSSSL case.  I don't see any strong
reason why sgml-mode + dsssl-mode would be harder than what he did.
I think making it work with psgml rather than the plain html-mode could
be a fair bit of work, OTOH.

While talking about ideas, I'd like to "merge" psgml-mode and sgml-mode.
What "merge" means here is not completely clear, but most likely it
means that psgml-mode would derive from sgml-mode, a bit like js2-mode
derives from js-mode nowadays.

> but I hardly write directly in HTML any more and I don't use PHP,
> so...  There's something about the NOTATION attribute giving the
> editor access to which major mode element content is in that lends
> itself to multi-major-mode.

I must admit that I don't know what you mean by "NOTATION attribute".

> At least, that's how I'd like to use psgml, but I need to learn a lot
> more about modes before I tried something like making emacs SGML-aware.

The SGML/XML support in Emacs is indeed in need of work.  Partly because
of the amount of distinct solutions reinventing the wheel slightly
differently (e.g. between sgml-mode, psgml-mode, nxml-mode, ...).


        Stefan

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [ELPA] Update package: psgml (discard patch)

Lucien Pullen
Also sprach Stefan Monnier on 2017-04-21:

>>> In the specific case of psgml, I think the real fix should be to make
>>> psgml interact more normally with font-lock.  I haven't looked into it
>>> hard enough yet, tho.
>> PSGML only understands the reference concrete syntax, so, with a few
>> exceptions such as for fontifying Null End Tags only when they can occur
>> and using the value of parameter entities for marked sections, it should
>> be able to use font lock using regular expressions.
>
> From a cursory look at how it currently works, I got the impression that
> it can be made to use font-lock without changing fundamentally how it's
> done.  Using regexps would probably be more painful, less efficient,
> and/or less reliable (luckily, font-lock is not limited to regexps).

I'm experimenting with converting it to regular font lock.  I set up sgml-set-face-for to check for font-lock-mode, and I'm thinking of aliasing sgml-fontify-buffer to font-lock-fontify-buffer.  Also playing with custom faces using defface instead of using sgml-markup-faces.

I tried using the syntax-table text property to syntactically fontify attribute values like how sgml-mode does and either made emacs spin or erased all fontification.  I'm sure if I try doing that when more awake it'll work better.  The answer probably involves not using the syntax-table text property.

I figured out where the default faces come from!  It's the font lock keywords that builtin sgml-mode uses.

>>> This makes me feel like you indeed have a multi-major-mode situation, in
>>> which case sgml-set-face is probably just one part of the problem (and
>>> using indirect buffers would just add more problems).
>> I've run into multi-major-mode a lot while doing SGML stuff.
>
> [ Side note: given the goal of SGML/XML to provide a kind of "universal
>   syntax", the frequency with which even things specifically designed
>   for XML/SGML end up using a completely different syntax (e.g. CSS,
>   RNC, DSSSL, etc...), seems to be a strong indication of failure.
>   Of course, that's just the opinion of someone who's never much liked
>   the SGML/XML tags because of their verbosity.  ]

I hate XML's verbosity with a passion.  I'm a big fan of all those minimization features that XML turned off.

I've been looking at using SGML as a structured container, like how DSSSL uses it, so most of the document is written in some format better suited to whatever it represents.  It doesn't reek of failure too much then.

>> I do miss MuMaMo integration with nHTML,
>
> Did MuMaMo disappear?

No, I just don't find myself using nHTML any more.

> BTW, Tom Tromey has recently added a new mhtml-mode to Emacs, which
> "simply" combines Emacs's html-mode js-mode and css-mode.  It won't
> directly help your dsssl-mode, but maybe you could try to see if his
> approach could be used for your SGML+DSSSL case.  I don't see any strong
> reason why sgml-mode + dsssl-mode would be harder than what he did.
> I think making it work with psgml rather than the plain html-mode could
> be a fair bit of work, OTOH.

Thanks, I'll look into it if I can find it.

> While talking about ideas, I'd like to "merge" psgml-mode and sgml-mode.
> What "merge" means here is not completely clear, but most likely it
> means that psgml-mode would derive from sgml-mode, a bit like js2-mode
> derives from js-mode nowadays.

I'm actually a bit curious about the differences between the two modes.  They basically do the same thing, but psgml uses its own buffer walker and builtin SGML uses syntax tables and regular expressions... lots of functions and variables named the same, so much so that I deleted sgml-mode.el because they kept stepping on each other.

I'm scrolling through builtin sgml-mode, and it looks like writing the builtin in terms of psgml would be easier than writing psgml in terms of the builtin.  I like the comment about what a valid comment is (though, I haven't read psgml's parse-comment to know if it's correct either... I assume it's better than builtin).

>> but I hardly write directly in HTML any more and I don't use PHP,
>> so...  There's something about the NOTATION attribute giving the
>> editor access to which major mode element content is in that lends
>> itself to multi-major-mode.
>
> I must admit that I don't know what you mean by "NOTATION attribute".

Basically, it specifies the syntax of content, like Emacs Lisp or C++.  When you feed your document to the application, the NOTATION attribute lets you communicate what program should parse the element instead of the SGML parser.

Back to your CSS comment, the TYPE attribute on the HTML LINK element would be a NOTATION attribute that lets you specify either CSS or (ugh) XSLT.

Also, psgml doesn't record notations.  I can get the public identifier for an entity, but not a notation.

>> At least, that's how I'd like to use psgml, but I need to learn a lot
>> more about modes before I tried something like making emacs SGML-aware.
>
> The SGML/XML support in Emacs is indeed in need of work.  Partly because
> of the amount of distinct solutions reinventing the wheel slightly
> differently (e.g. between sgml-mode, psgml-mode, nxml-mode, ...).

Well, they're good for different things.  nHTML gives you MuMaMo, which is a godsend for HTML-CSS-PHP-JS development.  sgml-mode is super fast and I find its html-mode and xml-mode almost too good.  psgml parses the document type definition similar to a full SGML parser, so it offers a lot of interactive editing help.

Too bad there's no Grand Unified SGML Library.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [ELPA] Update package: psgml (discard patch)

Stefan Monnier
>> BTW, Tom Tromey has recently added a new mhtml-mode to Emacs, which
>> "simply" combines Emacs's html-mode js-mode and css-mode.  It won't
>> directly help your dsssl-mode, but maybe you could try to see if his
>> approach could be used for your SGML+DSSSL case.  I don't see any strong
>> reason why sgml-mode + dsssl-mode would be harder than what he did.
>> I think making it work with psgml rather than the plain html-mode could
>> be a fair bit of work, OTOH.
> Thanks, I'll look into it if I can find it.

It's in Emacs's master branch (i.e. will be included in Emacs-26).

>> While talking about ideas, I'd like to "merge" psgml-mode and sgml-mode.
>> What "merge" means here is not completely clear, but most likely it
>> means that psgml-mode would derive from sgml-mode, a bit like js2-mode
>> derives from js-mode nowadays.
> I'm actually a bit curious about the differences between the two modes.
> They basically do the same thing, but psgml uses its own buffer walker and
> builtin SGML uses syntax tables and regular expressions... lots of functions
> and variables named the same, so much so that I deleted sgml-mode.el because
> they kept stepping on each other.

Yes, the naming is a problem.  It would probably make sense to rename
psgml's "sgml-" to "psgml-" as a first step towards sanity.


        Stefan


Loading...