Loading ...
Sorry, an error occurred while loading the content.

spell checking and xml:lang

Expand Messages
  • Vidar Gundersen
    can I use the xml:lang attribute to automatically select the appropriate ispell dictionary? should this kind of support for spell checking with ispell.el be a
    Message 1 of 6 , Nov 21, 2004
    • 0 Attachment
      can I use the xml:lang attribute to automatically select the
      appropriate ispell dictionary? should this kind of support
      for spell checking with ispell.el be a feature in nXML-mode?
    • usenet@heslin.eclipse.co.uk
      ... I have just written a package that does this for flyspell-mode (which uses ispell.el, but checks on the fly). I would guess that it would in fact be much
      Message 2 of 6 , Nov 22, 2004
      • 0 Attachment
        On 2004-11-21, Vidar Gundersen <vbg-list@...> wrote:
        >
        > can I use the xml:lang attribute to automatically select the
        > appropriate ispell dictionary? should this kind of support
        > for spell checking with ispell.el be a feature in nXML-mode?

        I have just written a package that does this for flyspell-mode (which
        uses ispell.el, but checks on the fly). I would guess that it would
        in fact be much simpler to implement what you describe, but I don't
        use ispell.el on its own myself.

        I wasn't really ready to release this package, since I haven't tested
        it much, but if you don't mind the possibility of running into a few
        bugs, you can get it here:

        http://www.dur.ac.uk/p.j.heslin/emacs/download/flyspell-xml-lang.el

        Best wishes,

        Peter
      • Vidar Gundersen
        ... very nice, i was able to test it briefly, but then after restarting emacs i started getting this error message, Symbol s function definition is void:
        Message 3 of 6 , Nov 22, 2004
        • 0 Attachment
          ===== Original message from usenet@... | Mon, 22 Nov 2004:
          > I have just written a package that does this for flyspell-mode
          > http://www.dur.ac.uk/p.j.heslin/emacs/download/flyspell-xml-lang.el

          very nice, i was able to test it briefly, but then after
          restarting emacs i started getting this error message,
          Symbol's function definition is void: exec-installed-p


          i put something like this in my xml-site.el setup
          to begin with (currently i have a problem telling the
          aspell/ispell.el combination to accept other dictionaries
          than the default):

          (add-hook 'nxml-mode-hook
          (lambda ()
          (save-excursion
          (when (search-forward-regexp "xml:lang=\"no\"" 250 0)
          (setq ispell-local-dictionary "norsk")))))


          Vidar___
        • Peter Heslin
          ... I don t know what that error is about, but if you are not using CVS Emacs, you may have to download and install up-to-date versions of ispell.el and
          Message 4 of 6 , Nov 23, 2004
          • 0 Attachment
            On 2004-11-22, Vidar Gundersen <vbg-list@...> wrote:
            >
            > ===== Original message from usenet@... | Mon, 22 Nov 2004:
            > > I have just written a package that does this for flyspell-mode
            > > http://www.dur.ac.uk/p.j.heslin/emacs/download/flyspell-xml-lang.el
            >
            > very nice, i was able to test it briefly, but then after
            > restarting emacs i started getting this error message,
            > Symbol's function definition is void: exec-installed-p

            I don't know what that error is about, but if you are not using CVS
            Emacs, you may have to download and install up-to-date versions of
            ispell.el and flyspell.el

            Peter
          • Vidar Gundersen
            ... i loaded flyspell-xml-lang.el prior to flyspell.el, my mistake. i ve ended up with the code below in my .emacs/xml-site.el, i m far from an elisp expert,
            Message 5 of 6 , Nov 23, 2004
            • 0 Attachment
              ===== Original message from Peter Heslin | Tue, 23 Nov 2004:
              > I don't know what that error is about, but if you are not using CVS
              > Emacs, you may have to download and install up-to-date versions of
              > ispell.el and flyspell.el

              i loaded flyspell-xml-lang.el prior to flyspell.el, my mistake.

              i've ended up with the code below in my .emacs/xml-site.el,
              i'm far from an elisp expert, but this seems to work. it's
              inspired by code in flyspell-xml-lang.el and takes advantake
              of flyspell-xml-lang-to-ispell-alist. thanks.

              Vidar___


              ;;; Switch flyspell language according to xml:lang attributes
              (require 'flyspell-xml-lang)
              (add-hook 'nxml-mode-hook 'flyspell-xml-lang-setup)

              ;;; Use xml:lang attribute to switch ispell language
              (defun count-chars-in-first-four-lines ()
              (interactive)
              (save-excursion
              (goto-char (point-min))
              (forward-line 4)
              (point)))
              (defun ispell-xml-lang-setup ()
              (save-excursion
              (when (search-forward-regexp "xml:lang=\"\\([^\"]+\\)\""
              (count-chars-in-first-four-lines))
              (setq lang (match-string 1))
              (let ((trans (assoc lang flyspell-xml-lang-to-ispell-alist))
              (buffer-modified-before (buffer-modified-p)))
              (when trans
              (setq ispell-local-dictionary (cadr trans)))))))

              (add-hook 'nxml-mode-hook 'ispell-xml-lang-setup )
            • drkm
              ... Maybe the following can interest you. It is a little bit more general. It read the value of the xml:lang attribute (conforming to RFC 3066), and look in
              Message 6 of 6 , Mar 8, 2005
              • 0 Attachment
                Vidar Gundersen <vbg-list@...> writes:

                > (add-hook 'nxml-mode-hook
                > (lambda ()
                > (save-excursion
                > (when (search-forward-regexp "xml:lang=\"no\"" 250 0)
                > (setq ispell-local-dictionary "norsk")))))

                Maybe the following can interest you. It is a little bit more
                general. It read the value of the xml:lang attribute (conforming to
                RFC 3066), and look in an alist for the associated dictionnary name.
                It is also a little bit more rigorous, in permitting spaces between
                "xml:lang", "=" and ['"], and check pairing of ' or ".

                Also, I incremented the bound in search-forward-regexp (250 is too
                less, think for examlpe about comments in the beginning of the file).
                IMHO, 2500 is not so an huge value for Emacs. In comparison, this
                message body count +/- 2000 characters.

                (defvar nxml-flyspell:xml-lang-to-ispell-lang-alist
                '(("no" . "norsk")
                ("en-US" . "american")
                ("en" . "english")
                ("fr" . "french"))
                "TODO: ...")

                (add-hook 'nxml-mode-hook
                (lambda ()
                (save-excursion
                (when (search-forward-regexp "xml:lang[ \t]*=[ \t]*['\"]" 2500 0)
                (looking-at
                (concat "\\(\\([a-zA-Z]\\{1,8\\}\\)\\(?:-[a-zA-Z0-9]\\{1,8\\}\\)*\\)"
                (char-to-string (char-before (point)))))
                (let ((lang (or (assoc (match-string 1)
                nxml-flyspell:xml-lang-to-ispell-lang-alist)
                (assoc (match-string 2)
                nxml-flyspell:xml-lang-to-ispell-lang-alist))))
                (when lang
                (setq ispell-local-dictionary lang)))))))

                --drkm
              Your message has been successfully submitted and would be delivered to recipients shortly.