emacs-evil / evil-collection

A set of keybindings for evil-mode

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add support for NXML mode

o0nd7ots opened this issue · comments

I had troubles commiting the changes but the code is here:

;;; evil-collection-nxml.el --- Evil bindings for nxml -*- lexical-binding: t -*-

;; Copyright (C) 2023 Zhiwei Chen

;; Author: o0nd7ots <o0nd7ots@4wrd.cc>
;; Maintainer: James Nguyen <james@jojojames.com>
;; Pierre Neidhardt <mail@ambrevar.xyz>
;; URL: https://github.com/emacs-evil/evil-collection
;; Version: 0.0.1
;; Package-Requires: ((emacs "26.3"))
;; Keywords: evil, nxml, tools

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:
;; Evil basic bindings for nxml-mode.  It's NOT intended to supersede
;; `evil-nxml-mode'.
;;

;;; Code:
(require 'evil-collection)

(defconst evil-collection-nxml-maps '(nxml-mode-map))

(declare-function nxml-backward-element "nxml")
(declare-function nxml-up-element "nxml")
(declare-function nxml-down-element "nxml")
(declare-function nxml-forward-element "nxml")
(declare-function nxml-toggle-level "nxml")
(defun nxml-toggle-level ()
  "Toggle folding/unfolding of the current XML tag using 'hs' in 'nxml-mode'."
  (interactive)
  (if (not (eq major-mode 'nxml-mode))
      (message "Not in nxml-mode")
    (progn (ignore-errors (nxml-forward-element))
	   (hs-toggle-hiding))))

;;;###autoload
(defun evil-collection-nxml-setup ()
  "Set up `evil' bindings for `nxml'."
  (evil-define-key 'normal nxml-mode-map
    (kbd "K") 'nxml-backward-element
    (kbd "H") 'nxml-up-element
    (kbd "L") 'nxml-down-element
    (kbd "J") 'nxml-forward-element
    (kbd "TAB") 'nxml-toggle-level
    (kbd "C-<tab>") 'hs-show-all))

(provide 'evil-collection-nxml)
;;; evil-collection-nxml.el ends here