Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Derive from prog-mode rather than text-mode #52

Closed
joewreschnig opened this issue Jul 26, 2017 · 9 comments
Closed

Derive from prog-mode rather than text-mode #52

joewreschnig opened this issue Jul 26, 2017 · 9 comments

Comments

@joewreschnig
Copy link

joewreschnig commented Jul 26, 2017

yaml-mode's derivation from text-mode causes my configuration to require more special-case hooks (and "unhooks") for yaml-mode than any other mode.

reST, HTML, Markdown, etc. (used to justify this derivation in #27) are markup languages. A document is primarily text intended for direct reading, surrounded by formal markup. YAML is, as it states, not. It's a language specifying structure, sometimes containing human-readable text (but often not).

I don't want to spellcheck anything but comments. I don't want to electrify any quotes or typographic punctuation. I want flycheck to complain loudly about syntax errors. In every respect, I want to act like a prog-mode.

@wasamasa
Copy link
Collaborator

I consider YAML to be of the same class as HTML and XML, structured, mostly readable and with a fair amount of syntax. Considering that they derive from text-mode, not doing so for YAML requires extraordinary reasons. I'm only aware of css-mode going the other way and becoming prog-mode-derived.

Generally speaking, I find text-mode an odd beast to derive from. At what point does it stop being prose and start rivaling a programming language? Is it when you need to parse the file to make sense of it? Due to this I'm using flycheck only for more specific modes, the same approach works for electric quotes and typographic punctuation. Putting functions on text-mode-hook only works for the most general stuff anyway.

@joewreschnig
Copy link
Author

I'm only aware of css-mode going the other way and becoming prog-mode-derived.

Scanning MELPA and modes I use regularly:

  • prog-mode: web-mode, json-mode, ini-mode, haml-mode, qml-mode
  • conf-mode: toml-mode
  • text-mode: dokuwiki-mode and other wiki modes, markdown-mode, rst-mode, nxml-mode (but it's traditionally targeted at DocBook/XHTML-style uses, not e.g. Java config files), html-mode (but I don't think it's a coincidence that web-mode has replaced this for many people)

Do you really think YAML looks more like reST and HTML than it does JSON, HAML, or QML?

At what point does it stop being prose and start rivaling a programming language?

This line is fuzzy, but I think YAML is so far on the prog side debating its exact cut doesn't matter. Even the name disclaims its abilities to mark up text. To flip the question around, where have you written YAML that could be considered "mostly prose?"

Due to this I'm using flycheck only for more specific modes, the same approach works for electric quotes and typographic punctuation.

There is no mode more specific than text-mode for .txt files.

I won't argue further, but I think this is a decision that causes a lot of annoyances, and I can't see any gain.

@wasamasa
Copy link
Collaborator

Do you really think YAML looks more like reST and HTML than it does JSON, HAML, or QML?

It's somewhere between reST and JSON, although json-mode is only indirectly derived from prog-mode because it's a nobrainer to derive from javascript-mode to get syntax highlighting and whatnot for free.

To flip the question around, where have you written YAML that could be considered "mostly prose?"

These days I'm mostly using it for localization files

@mmckinst
Copy link
Contributor

mmckinst commented Dec 9, 2019

I think deriving from prog-mode also makes more sense.

YAML is a data serialization language, much like JSON, INI, HAML, and QML which all derive from prog-mode.

HTML, RST, and Markdown are all markup languages that derive from text-mode which makes sense because its primarily text with some markup added.

YAML doesn't mark up text. While YAML can used to write prose, its primary function is serialization.

If its going to stay derived from text-mode, would you be open to adding something to the docs about how to derive from prog-mode for the people that want to do so?

@wasamasa
Copy link
Collaborator

wasamasa commented Dec 9, 2019

I don't plan on changing that this late after making the decision, with several releases in. I don't think it's as big of an issue as you make it to be either. If you find a solution, feel free to post it in here.

@yugaego
Copy link

yugaego commented Aug 5, 2021

yaml-mode's derivation from text-mode causes my configuration to require more special-case hooks (and "unhooks")

I'm experiencing the same trouble.

Since the last comment (from the last maintainer I assume?) states

I don't plan on changing that this late after making the decision, with several releases in. I don't think it's as big of an issue as you make it to be either. If you find a solution, feel free to post it in here.

and PR #85 was rejected,

possible workarounds (with their own disadvantages) I currently see are:

[EDIT] link to related issue #17 and PR #18 .

@wasamasa
Copy link
Collaborator

wasamasa commented Aug 5, 2021

There is a much easier workaround: Just add whatever you have in prog-mode-hook that's acceptable to have for YAML files to yaml-mode-hook.

@yugaego
Copy link

yugaego commented Aug 5, 2021

There is a much easier workaround: Just add whatever you have in prog-mode-hook that's acceptable to have for YAML files to yaml-mode-hook.

Yes, I agree it'd be nice to utilize yaml-mode-hook, but its usage doesn't fix the use case of having text-mode-hook configurations messing up with yaml files as a consequence of yaml-mode deriving from text-mode, does it?

[I believe OP described enough quantity of exact issues, I've got quite the same ones: customization I'd expect to be applied to a natural language text only are applied to an artificial language text with yaml-mode.]

So, for such cases, I assume the correct workarounds (probably not all possible) were listed in my previous comment.

@ThibautVerron
Copy link

As a user-level workaround, something similar to this should also in principle work.

(defun replace-text-with-prog-hook ()
   (kill-all-local-variables)
   (remove-hook 'yaml-mode-hook 'replace-text-with-prog-hook)
   (let ((text-mode-hook nil))
     (yaml-mode))
   (add-hook 'yaml-mode-hook 'replace-text-with-prog-hook)
   (run-hooks 'prog-mode-hook))

(add-hook 'yaml-mode-hook 'replace-text-with-prog-hook)

It doesn't quite work at it is (or, to be precise, it only works once), just leaving it here in case it's useful to someone else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants