first commit

This commit is contained in:
Yura 2024-09-15 15:12:16 +03:00
commit 417e54da96
5696 changed files with 900003 additions and 0 deletions

View file

@ -0,0 +1,9 @@
'''
Syntax Highlighting
===================
This module contains various files for providing Kivy syntax highlighting in
some popular text editors. Please see the contents of this folder for the
provided resources.
'''

View file

@ -0,0 +1,293 @@
;;; kivy-mode.el --- Emacs major mode for editing Kivy files
;;
;; Author: Dean Serenevy <dean@serenevy.net>
;; Version: 0.1.0
;;
;; This document borrowed heavily from yaml-mode.el by Yoshiki Kurihara and
;; Marshall Vandegrift.
;;
;; This file is not part of Emacs
;; This file 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; version 3.
;; This file 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 GNU Emacs; see the file COPYING. If not, write to the Free Software
;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
;; USA.
;;; Installation:
;; To install, just drop this file into a directory in your `load-path' and
;; (optionally) byte-compile it. To automatically handle files ending in
;; '.kv', add something like:
;;
;; (require 'kivy-mode)
;; (add-to-list 'auto-mode-alist '("\\.kv$" . kivy-mode))
;;
;; to your .emacs file.
;;
;; This mode does not enable electric-indent by default. To get this
;; behavior, either enable electric-indent-mode globally or enable it only
;; for kivy buffers using `kivy-mode-hook':
;;
;; (add-hook 'kivy-mode-hook
;; '(lambda ()
;; (electric-indent-local-mode t)))
;; User definable variables
(defgroup kivy nil
"Support for the kivy user interface definition format"
:group 'languages
:prefix "kivy-")
(defcustom kivy-mode-hook nil
"*Hook run by `kivy-mode'."
:type 'hook
:group 'kivy)
(defcustom kivy-indent-offset 4
"*Amount of offset per level of indentation."
:type 'integer
:group 'kivy)
(defcustom kivy-backspace-function 'backward-delete-char-untabify
"*Function called by `kivy-electric-backspace' when deleting backwards."
:type 'function
:group 'kivy)
(defface kivy-tab-face
'((((class color)) (:background "red" :foreground "red" :bold t))
(t (:reverse-video t)))
"Face to use for highlighting tabs in kivy files."
:group 'faces
:group 'kivy)
(defcustom kivy-imenu-generic-expression
'((nil "^\\([<>a-zA-Z_-]+\\):" 1))
"The imenu regex to parse an outline of the kivy file."
:type 'string
:group 'kivy)
;; Constants
(defconst kivy-mode-version "0.1.0" "Version of `kivy-mode.'")
(defconst kivy-blank-line-re "^ *$"
"Regexp matching a line containing only (valid) whitespace.")
(defconst kivy-comment-re "\\(?:^\\|\\s-+\\)\\(#.*\\)"
"Regexp matching a line containing a kivy comment or delimiter.")
(defconst kivy-directive-re "^\\(?:#:\\)\\(\\w+ +.*\\)"
"Regexp matching a line containing a kivy directive.")
(defconst kivy-tag-re "^ *id: *\\([^ \n]+\\)$"
"Rexexp matching a kivy tag.")
(defconst kivy-bare-scalar-re
"\\(?:[^-:,#!\n{\\[ ]\\|[^#!\n{\\[ ]\\S-\\)[^#\n]*?"
"Rexexp matching a kivy bare scalar.")
(defconst kivy-hash-key-re
(concat "^ *"
"\\(" kivy-bare-scalar-re "\\) *:"
"\\(?: +\\|$\\)")
"Regexp matching a single kivy hash key.")
(defconst kivy-nested-map-re
(concat ".*: *$")
"Regexp matching a line beginning a kivy nested structure.")
(defconst kivy-constant-scalars-re
(concat "\\(?:^\\|\\(?::\\|-\\|,\\|{\\|\\[\\) +\\) *"
(regexp-opt
'("True" "False" "None") t)
" *$")
"Regexp matching certain scalar constants in scalar context")
;; Mode setup
(defvar kivy-mode-map ()
"Keymap used in `kivy-mode' buffers.")
(if kivy-mode-map
nil
(setq kivy-mode-map (make-sparse-keymap))
(define-key kivy-mode-map [backspace] 'kivy-electric-backspace)
(define-key kivy-mode-map "\C-c<" 'kivy-indent-shift-left)
(define-key kivy-mode-map "\C-c>" 'kivy-indent-shift-right)
)
(defvar kivy-mode-syntax-table nil
"Syntax table in use in kivy-mode buffers.")
(if kivy-mode-syntax-table
nil
(setq kivy-mode-syntax-table (make-syntax-table))
(modify-syntax-entry ?\' "\"" kivy-mode-syntax-table)
(modify-syntax-entry ?\" "\"" kivy-mode-syntax-table)
(modify-syntax-entry ?# "<" kivy-mode-syntax-table)
(modify-syntax-entry ?\n ">" kivy-mode-syntax-table)
(modify-syntax-entry ?\\ "\\" kivy-mode-syntax-table)
(modify-syntax-entry ?- "_" kivy-mode-syntax-table)
(modify-syntax-entry ?_ "w" kivy-mode-syntax-table)
(modify-syntax-entry ?< "." kivy-mode-syntax-table)
(modify-syntax-entry ?> "." kivy-mode-syntax-table)
(modify-syntax-entry ?_ "_" kivy-mode-syntax-table)
)
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.kv$" . kivy-mode))
;;;###autoload
(define-derived-mode kivy-mode fundamental-mode "kivy"
"Simple mode to edit kivy.
\\{kivy-mode-map}"
(set (make-local-variable 'comment-start) "# ")
(set (make-local-variable 'comment-start-skip) "#+ *")
(set (make-local-variable 'indent-line-function) 'kivy-indent-line)
(set (make-local-variable 'font-lock-defaults)
'(kivy-font-lock-keywords
nil nil nil nil
(font-lock-syntactic-keywords))))
;; Font-lock support
(defvar kivy-font-lock-keywords
(list
(cons kivy-comment-re '(1 font-lock-comment-face))
(cons kivy-constant-scalars-re '(1 font-lock-constant-face))
(cons kivy-tag-re '(1 font-lock-function-name-face))
(cons kivy-hash-key-re '(1 font-lock-variable-name-face t))
(cons kivy-directive-re '(1 font-lock-builtin-face))
'("^[\t]+" 0 'kivy-tab-face t))
"Additional expressions to highlight in kivy mode.")
(defvar kivy-font-lock-syntactic-keywords
(list '())
"Additional syntax features to highlight in kivy mode.")
;; Indentation and electric keys
(defun kivy-compute-indentation ()
"Calculate the maximum sensible indentation for the current line."
(save-excursion
(beginning-of-line)
(forward-line -1)
(while (and (looking-at kivy-blank-line-re)
(> (point) (point-min)))
(forward-line -1))
(+ (current-indentation)
(if (looking-at kivy-nested-map-re) kivy-indent-offset 0)
)))
(defun kivy-indent-line ()
"Indent the current line.
The first time this command is used, the line will be indented to the
maximum sensible indentation. Each immediately subsequent usage will
back-dent the line by `kivy-indent-offset' spaces. On reaching column
0, it will cycle back to the maximum sensible indentation."
(interactive "*")
(let ((ci (current-indentation))
(cc (current-column))
(need (kivy-compute-indentation)))
(save-excursion
(beginning-of-line)
(delete-horizontal-space)
(if (and (equal last-command this-command) (/= ci 0))
(indent-to (* (/ (- ci 1) kivy-indent-offset) kivy-indent-offset))
(indent-to need)))
(if (< (current-column) (current-indentation))
(forward-to-indentation 0))))
(defun kivy-electric-backspace (arg)
"Delete characters or back-dent the current line.
If invoked following only whitespace on a line, will back-dent to the
immediately previous multiple of `kivy-indent-offset' spaces."
(interactive "*p")
(if (or (/= (current-indentation) (current-column)) (bolp))
(funcall kivy-backspace-function arg)
(let ((ci (current-column)))
(beginning-of-line)
(delete-horizontal-space)
(indent-to (* (/ (- ci (* arg kivy-indent-offset))
kivy-indent-offset)
kivy-indent-offset)))))
(defun kivy-set-imenu-generic-expression ()
(make-local-variable 'imenu-generic-expression)
(make-local-variable 'imenu-create-index-function)
(setq imenu-create-index-function 'imenu-default-create-index-function)
(setq imenu-generic-expression kivy-imenu-generic-expression))
(add-hook 'kivy-mode-hook 'kivy-set-imenu-generic-expression)
(add-hook 'kivy-mode-hook
'(lambda ()
(setq indent-tabs-mode 'nil)))
(defun kivy-mode-version ()
"Display version of `kivy-mode'."
(interactive)
(message "kivy-mode %s" kivy-mode-version)
kivy-mode-version)
(defun kivy-indent-shift-left (start end &optional count)
"Shift lines contained in region START END by COUNT columns to the left.
COUNT defaults to `kivy-indent-offset'. If region isn't
active, the current line is shifted. The shifted region includes
the lines in which START and END lie. An error is signaled if
any lines in the region are indented less than COUNT columns."
(interactive
(if mark-active
(list (region-beginning) (region-end) current-prefix-arg)
(list (line-beginning-position) (line-end-position) current-prefix-arg)))
(if count
(setq count (prefix-numeric-value count))
(setq count kivy-indent-offset))
(when (> count 0)
(let ((deactivate-mark nil))
(save-excursion
(goto-char start)
(while (< (point) end)
(if (and (< (current-indentation) count)
(not (looking-at "[ \t]*$")))
(error "Can't shift all lines enough"))
(forward-line))
(indent-rigidly start end (- count))))))
(defun kivy-indent-shift-right (start end &optional count)
"Shift lines contained in region START END by COUNT columns to the left.
COUNT defaults to `kivy-indent-offset'. If region isn't
active, the current line is shifted. The shifted region includes
the lines in which START and END lie."
(interactive
(if mark-active
(list (region-beginning) (region-end) current-prefix-arg)
(list (line-beginning-position) (line-end-position) current-prefix-arg)))
(let ((deactivate-mark nil))
(if count
(setq count (prefix-numeric-value count))
(setq count kivy-indent-offset))
(indent-rigidly start end count)))
(provide 'kivy-mode)
;;; kivy-mode.el ends here

View file

@ -0,0 +1,20 @@
{ "name": "Kivy Language",
"scopeName": "source.python.kivy",
"fileTypes": ["kv"],
"patterns": [
{ "match": "#:.*?$",
"name": "support.type.kivy" },
{ "match": "#.*?$",
"name": "comment.kivy" },
{ "match": "\\<.+\\>",
"name": "support.class.kivy" },
{ "match": "[A-Za-z][A-Za-z0-9]+$",
"name": "support.function.kivy" },
{ "match": ".*?:$",
"name": "support.function.kivy" },
{ "name": "entity.name.section.kivy",
"match": "(.*?):$" },
{ "include": "source.python" }
],
"uuid": "49cecc44-5094-48ec-a876-91f597e8bf81"
}

View file

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>fileTypes</key>
<array>
<string>kv</string>
</array>
<key>name</key>
<string>Kivy Language</string>
<key>patterns</key>
<array>
<dict>
<key>match</key>
<string>#:.*?$</string>
<key>name</key>
<string>support.type.kivy</string>
</dict>
<dict>
<key>match</key>
<string>#.*?$</string>
<key>name</key>
<string>comment.kivy</string>
</dict>
<dict>
<key>match</key>
<string>\&lt;.+\&gt;</string>
<key>name</key>
<string>support.class.kivy</string>
</dict>
<dict>
<key>match</key>
<string>[A-Za-z][A-Za-z0-9]+$</string>
<key>name</key>
<string>support.function.kivy</string>
</dict>
<dict>
<key>match</key>
<string>.*?:$</string>
<key>name</key>
<string>support.function.kivy</string>
</dict>
<dict>
<key>match</key>
<string>(.*?):$</string>
<key>name</key>
<string>entity.name.section.kivy</string>
</dict>
<dict>
<key>include</key>
<string>source.python</string>
</dict>
</array>
<key>scopeName</key>
<string>source.python.kivy</string>
<key>uuid</key>
<string>49cecc44-5094-48ec-a876-91f597e8bf81</string>
</dict>
</plist>

View file

@ -0,0 +1,47 @@
" ~/.vim/after/syntax/kivy.vim
"
" Vim syntax file
" Language: Kivy
" Maintainer: Gabriel Pettier <gabriel.pettier@gmail.com>
" Last Change: 2020 June 23
syntax clear
syn include @pyth $VIMRUNTIME/syntax/python.vim
syn match kivyComment /#.*\n/ display contains=pythonTodo,Spell
syn match kivyPreProc /^\s*#:.*/
syn match kivyRule /<-*\I\i*\%([,@+]\I\i*\)*>:/
syn match kivyRule /\[-*\I\i*\%([,@+]\I\i*\)*]:/
syn match kivyRootRule /^\I\i*:\s*$/
syn region kivyAttrBlock matchgroup=kivyAttribute start=/^\z(\s\+\)\I\i*\s*:\s*$/ skip="^\s*$" end="^\%(\z1\s\{4}\)\@!" contains=@pyth
syn region kivyAttrBlock matchgroup=kivyAttribute start=/^\s\+\I\i*\s*:\%(\s*\S\)\@=/ end="$" keepend oneline contains=@pyth
syn region kivyId matchgroup=kivyAttribute start=/^\s\+id\s*:\s*/ end="\w\+\zs" oneline
syn region kivyBindBlock matchgroup=kivyBind start=/^\z(\s\+\)on_\I\i*\s*:\s*$/ skip="^\s*$" end="^\%(\z1\s\{4}\)\@!" contains=@pyth
syn region kivyBindBlock matchgroup=kivyBind start=/^\s\+on_\i\+\s*:\%(\s*\S\)\@=/ end="$" keepend oneline contains=@pyth
syn region kivyCanvasValue matchgroup=kivyCanvas start=/^\z(\s\+\)\I\i*\s*:\s*$/ skip="^\s*$" end="^\%(\z1\s\{4}\)\@!" contains=@pyth contained
syn region kivyCanvasValue matchgroup=kivyCanvas start=/^\s\+\I\i*\s*:\%(\s*\S\)\@=/ end="$" keepend oneline contains=@pyth contained
syn region kivyCanvas matchgroup=kivyCanvas start=/^\z(\s\+\)canvas.*:\s*$/ skip="^\s*$" end="^\%(\z1\s\{4}\)\@!"
\ contains=kivyInstruction,kivyPreProc,kivyComment,kivyCanvasValue
syn match kivyInstruction /^\s\+\u\i*\s*:/ contained
syn match kivyWidget /^\s\+\u\i*\s*:/
hi def link kivyPreproc PreProc
hi def link kivyComment Comment
hi def link kivyRule Type
hi def link kivyRootRule Function
hi def link kivyAttribute Label
hi def link kivyBind Function
hi def link kivyWidget Function
hi def link kivyCanvas special
hi def link kivyInstruction Statement
hi KivyId cterm=underline
hi KivyPreproc cterm=bold
let b:current_syntax = "kivy"