Docbook Editor Configuration: Difference between revisions

From NixOS Wiki
imported>Fadenb
No edit summary
m fix syntax highlighting errors
 
(8 intermediate revisions by 5 users not shown)
Line 1: Line 1:
{{outdated|This page may not see useful updates now that NixOS and Nixpkgs use markdown as the authoring format of the documentation.<br />The content may still be accurate.}}
==For Vim/Neovim==
<syntaxhighlight lang="nix">
(pkgs.neovim.override {
  configure.packages.myplugins.start = with pkgs.vimPlugins; [
    vim-docbk
    vim-docbk-snippets
    syntastic
    UltiSnips
  ];
})
</syntaxhighlight>
== For Emacs ==
== For Emacs ==


The following creates an Emacs with a custom module, which configures nXML for the NixOS / Nixpkgs docbook codebase:
The following creates an Emacs with a custom module, which configures nXML for the NixOS / Nixpkgs docbook codebase:


  let
<syntaxhighlight lang="nix">
    pkgs = import <nixpkgs> {};
let
    inherit (pkgs) emacsPackagesNg docbook5 writeText;
  pkgs = import <nixpkgs> {};
  inherit (pkgs) emacsPackagesNg docbook5 writeText;
    schemas = writeText "schemas.xml" ''
 
      <locatingRules xmlns="http://thaiopensource.com/ns/locating-rules/1.0">
  schemas = writeText "schemas.xml" ''
        <documentElement localName="section" typeId="DocBook"/>
    <locatingRules xmlns="http://thaiopensource.com/ns/locating-rules/1.0">
        <documentElement localName="chapter" typeId="DocBook"/>
      <documentElement localName="section" typeId="DocBook"/>
        <documentElement localName="article" typeId="DocBook"/>
      <documentElement localName="chapter" typeId="DocBook"/>
        <documentElement localName="book" typeId="DocBook"/>
      <documentElement localName="article" typeId="DocBook"/>
        <typeId id="DocBook" uri="${docbook5}/xml/rng/docbook/docbookxi.rnc" />
      <documentElement localName="book" typeId="DocBook"/>
      </locatingRules>
      <typeId id="DocBook" uri="${docbook5}/xml/rng/docbook/docbookxi.rnc" />
    '';
    </locatingRules>
  '';
  in emacsPackagesNg.emacsWithPackages (epkgs: [
 
    (emacsPackagesNg.trivialBuild {
in emacsPackagesNg.emacsWithPackages (epkgs: [
      pname = "nix-docbook-mode";
  (emacsPackagesNg.trivialBuild {
      version = "1970-01-01";
    pname = "nix-docbook-mode";
      src = writeText "default.el" ''
    version = "1970-01-01";
        (eval-after-load 'rng-loc
    src = writeText "default.el" ''
          '(add-to-list 'rng-schema-locating-files "${schemas}"))
      (eval-after-load 'rng-loc
      '';
        '(add-to-list 'rng-schema-locating-files "${schemas}"))
    })
    '';
  ])
  })
])
</syntaxhighlight>
 
== For IntelliJ IDEA (Community and Ultimate) ==
 
First off, the feature set for XML and Docbook editing is the same in both versions. Here's a neat one-liner to start the Community edition
 
<syntaxhighlight lang="console">
nix-shell -p jetbrains.idea-community --run idea-community
</syntaxhighlight>
 
Then, open the <tt>doc/</tt> or root folder of the <tt>&lt;nixpkgs&gt;</tt> project. (Opening a file directly will not allow browsing the directory structure within the IDE.
 
[[File:Docbook-intellij-open.png]]
 
=== Adding the docbook schema ===
 
At the root of <tt>&lt;nixpkgs&gt;</tt>, run the following command. It will create a link to docbook, allowing (easier) use of the
xsd files. The symlink can be updated instead of having to change the full store path in the editor. The second command will print the full path to the docbook xsd.
 
<syntaxhighlight lang="console">
$ nix-build -A docbook5 --out-link docbook
$ echo $PWD/docbook/share/xml/docbook-5.0/xsd/docbook.xsd
</syntaxhighlight>
 
Open <tt>manual.xml</tt>. After a short while, IntelliJ IDEA will realise it does not know about the schema.
 
[[File:Docbook-intellij-schema-error.png]]
 
Click on the red light bulb, then <em>Manually setup an external resource</em>.
 
[[File:Docbook-intellij-bulb-menu.png]]
 
Paste in the full path to the <tt>xsd</tt> file.
 
[[File:Docbook-intellij-full-path.png]]
 
After this is done, IntelliJ will validate.
 
[[File:Docbook-intellij-mistake.png]]

Latest revision as of 18:45, 21 June 2024

For Vim/Neovim

(pkgs.neovim.override {
   configure.packages.myplugins.start = with pkgs.vimPlugins; [
     vim-docbk
     vim-docbk-snippets
     syntastic
     UltiSnips
   ];
 })

For Emacs

The following creates an Emacs with a custom module, which configures nXML for the NixOS / Nixpkgs docbook codebase:

let
  pkgs = import <nixpkgs> {};
  inherit (pkgs) emacsPackagesNg docbook5 writeText;

  schemas = writeText "schemas.xml" ''
    <locatingRules xmlns="http://thaiopensource.com/ns/locating-rules/1.0">
      <documentElement localName="section" typeId="DocBook"/>
      <documentElement localName="chapter" typeId="DocBook"/>
      <documentElement localName="article" typeId="DocBook"/>
      <documentElement localName="book" typeId="DocBook"/>
      <typeId id="DocBook" uri="${docbook5}/xml/rng/docbook/docbookxi.rnc" />
    </locatingRules>
  '';

in emacsPackagesNg.emacsWithPackages (epkgs: [
  (emacsPackagesNg.trivialBuild {
    pname = "nix-docbook-mode";
    version = "1970-01-01";
    src = writeText "default.el" ''
      (eval-after-load 'rng-loc
        '(add-to-list 'rng-schema-locating-files "${schemas}"))
    '';
  })
])

For IntelliJ IDEA (Community and Ultimate)

First off, the feature set for XML and Docbook editing is the same in both versions. Here's a neat one-liner to start the Community edition

nix-shell -p jetbrains.idea-community --run idea-community

Then, open the doc/ or root folder of the <nixpkgs> project. (Opening a file directly will not allow browsing the directory structure within the IDE.

Adding the docbook schema

At the root of <nixpkgs>, run the following command. It will create a link to docbook, allowing (easier) use of the xsd files. The symlink can be updated instead of having to change the full store path in the editor. The second command will print the full path to the docbook xsd.

$ nix-build -A docbook5 --out-link docbook
$ echo $PWD/docbook/share/xml/docbook-5.0/xsd/docbook.xsd

Open manual.xml. After a short while, IntelliJ IDEA will realise it does not know about the schema.

Click on the red light bulb, then Manually setup an external resource.

Paste in the full path to the xsd file.

After this is done, IntelliJ will validate.