obsolete/dict-c5-mode.el
author Oleksandr Gavenko <gavenkoa@gmail.com>
Thu, 15 Sep 2016 20:13:18 +0300
changeset 558 53fd793e345d
parent 335 8732c7c894af
permissions -rw-r--r--
Add shortcut to deploy to HG repos.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
320
4272023569f3 major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     1
;;; dict-mode.el --- major mode for dict dictionary source files
4272023569f3 major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     2
4272023569f3 major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     3
;; Copyright (C) 2011 by Oleksandr Gavenko <gavenkoa@gmail.com>
4272023569f3 major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     4
4272023569f3 major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     5
;; You can do anything with this file without any warranty.
4272023569f3 major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     6
4272023569f3 major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     7
;; Author: Oleksandr Gavenko <gavenkoa@gmail.com>
4272023569f3 major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     8
;; Maintainer: Oleksandr Gavenko <gavenkoa@gmail.com>
4272023569f3 major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     9
;; Created: 2011-09-04
4272023569f3 major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    10
;; Version: 0.1
4272023569f3 major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    11
;; Keywords: dict, dictionary
4272023569f3 major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    12
4272023569f3 major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    13
;;; Commentary:
4272023569f3 major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    14
;;
4272023569f3 major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    15
;; Very pure release.
4272023569f3 major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    16
4272023569f3 major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    17
;;; Code:
4272023569f3 major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    18
324
b00f5057ca3c Rewrite code to use 'define-derived-mode'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 323
diff changeset
    19
(defvar dict-c5-font-lock-keywords
331
b69b69ac7457 Remove debug code.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 330
diff changeset
    20
  '(
b69b69ac7457 Remove debug code.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 330
diff changeset
    21
    ("^\\(_\\{5,\\}\\)\n\n\\(\\w.*\\)$"
b69b69ac7457 Remove debug code.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 330
diff changeset
    22
     (1 font-lock-function-name-face) (2 font-lock-keyword-face))
332
49545a5764ef Remove newline from allowed transcription chars.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 331
diff changeset
    23
    ("\\[[^]\n]+]" . font-lock-type-face)
331
b69b69ac7457 Remove debug code.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 330
diff changeset
    24
    ))
320
4272023569f3 major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    25
334
95ccf76a6c7f Fix: Warning: assignment to free variable `dict-c5-mode-map'
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 333
diff changeset
    26
(eval-when-compile
95ccf76a6c7f Fix: Warning: assignment to free variable `dict-c5-mode-map'
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 333
diff changeset
    27
  (defvar font-lock-beg)
95ccf76a6c7f Fix: Warning: assignment to free variable `dict-c5-mode-map'
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 333
diff changeset
    28
  (defvar font-lock-end))
95ccf76a6c7f Fix: Warning: assignment to free variable `dict-c5-mode-map'
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 333
diff changeset
    29
325
e64b740278c5 Finally fix multiline highlighting.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 324
diff changeset
    30
(defun dict-c5-font-lock-extend-region ()
326
7b4a2a55729a Add docs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 325
diff changeset
    31
  "Look for '_____' expression and extend `font-lock-beg' and `font-lock-end'."
329
410c26a389a6 Fix highlighting near beginning and end of buffer.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 328
diff changeset
    32
  ;; (message "%d:%d, %d lines" font-lock-beg font-lock-end (count-lines font-lock-beg font-lock-end))
328
80146b5ba6e6 Fix infinite invocation of 'dict-c5-font-lock-extend-region' by guarding condition.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 327
diff changeset
    33
  (cond
80146b5ba6e6 Fix infinite invocation of 'dict-c5-font-lock-extend-region' by guarding condition.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 327
diff changeset
    34
   ((and
80146b5ba6e6 Fix infinite invocation of 'dict-c5-font-lock-extend-region' by guarding condition.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 327
diff changeset
    35
     (< (count-lines font-lock-beg font-lock-end) 5)
329
410c26a389a6 Fix highlighting near beginning and end of buffer.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 328
diff changeset
    36
     (not (and (<= (point-max) font-lock-end) (<= font-lock-beg (point-min)) )))
325
e64b740278c5 Finally fix multiline highlighting.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 324
diff changeset
    37
    (save-excursion
e64b740278c5 Finally fix multiline highlighting.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 324
diff changeset
    38
      (goto-char font-lock-beg)
e64b740278c5 Finally fix multiline highlighting.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 324
diff changeset
    39
      (forward-line -2)
328
80146b5ba6e6 Fix infinite invocation of 'dict-c5-font-lock-extend-region' by guarding condition.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 327
diff changeset
    40
      (setq font-lock-beg (point))
80146b5ba6e6 Fix infinite invocation of 'dict-c5-font-lock-extend-region' by guarding condition.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 327
diff changeset
    41
      (goto-char font-lock-end)
80146b5ba6e6 Fix infinite invocation of 'dict-c5-font-lock-extend-region' by guarding condition.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 327
diff changeset
    42
      (forward-line 3)
80146b5ba6e6 Fix infinite invocation of 'dict-c5-font-lock-extend-region' by guarding condition.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 327
diff changeset
    43
      (setq font-lock-end (point))
327
21124e46bf6e Return non-nil if region was adjusted.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 326
diff changeset
    44
      )
328
80146b5ba6e6 Fix infinite invocation of 'dict-c5-font-lock-extend-region' by guarding condition.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 327
diff changeset
    45
    t)
80146b5ba6e6 Fix infinite invocation of 'dict-c5-font-lock-extend-region' by guarding condition.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 327
diff changeset
    46
   (t nil)
80146b5ba6e6 Fix infinite invocation of 'dict-c5-font-lock-extend-region' by guarding condition.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 327
diff changeset
    47
   ))
325
e64b740278c5 Finally fix multiline highlighting.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 324
diff changeset
    48
335
8732c7c894af dict-c5-new-entry
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 334
diff changeset
    49
(defun dict-c5-new-entry ()
8732c7c894af dict-c5-new-entry
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 334
diff changeset
    50
  "Insert new entry template."
8732c7c894af dict-c5-new-entry
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 334
diff changeset
    51
  (interactive)
8732c7c894af dict-c5-new-entry
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 334
diff changeset
    52
  (if (re-search-forward "^_____" nil t)
8732c7c894af dict-c5-new-entry
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 334
diff changeset
    53
      (beginning-of-line)
8732c7c894af dict-c5-new-entry
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 334
diff changeset
    54
    (goto-char (point-max)))
8732c7c894af dict-c5-new-entry
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 334
diff changeset
    55
  (while (eq (char-before) ?\n)
8732c7c894af dict-c5-new-entry
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 334
diff changeset
    56
    (delete-backward-char 1))
8732c7c894af dict-c5-new-entry
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 334
diff changeset
    57
  (insert-char ?\n)
8732c7c894af dict-c5-new-entry
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 334
diff changeset
    58
  (insert-char ?_ 5)
8732c7c894af dict-c5-new-entry
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 334
diff changeset
    59
  (insert-char ?\n 3)
8732c7c894af dict-c5-new-entry
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 334
diff changeset
    60
  (backward-char))
8732c7c894af dict-c5-new-entry
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 334
diff changeset
    61
8732c7c894af dict-c5-new-entry
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 334
diff changeset
    62
(defvar dict-c5-mode-map (make-sparse-keymap))
8732c7c894af dict-c5-new-entry
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 334
diff changeset
    63
(define-key dict-c5-mode-map [C-return] 'dict-c5-new-entry)
8732c7c894af dict-c5-new-entry
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 334
diff changeset
    64
320
4272023569f3 major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    65
;;;###autoload
324
b00f5057ca3c Rewrite code to use 'define-derived-mode'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 323
diff changeset
    66
(define-derived-mode dict-c5-mode fundamental-mode "Dict-c5"
b00f5057ca3c Rewrite code to use 'define-derived-mode'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 323
diff changeset
    67
  "Derived mode for editing C5 dictd source file."
b00f5057ca3c Rewrite code to use 'define-derived-mode'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 323
diff changeset
    68
  (add-to-list 'auto-mode-alist (cons "\\.dict-c5$" 'dict-c5-mode))
b00f5057ca3c Rewrite code to use 'define-derived-mode'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 323
diff changeset
    69
  (setq font-lock-defaults
b00f5057ca3c Rewrite code to use 'define-derived-mode'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 323
diff changeset
    70
        '(dict-c5-font-lock-keywords
b00f5057ca3c Rewrite code to use 'define-derived-mode'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 323
diff changeset
    71
          t nil nil nil
b00f5057ca3c Rewrite code to use 'define-derived-mode'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 323
diff changeset
    72
          (font-lock-multiline . t)
b00f5057ca3c Rewrite code to use 'define-derived-mode'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 323
diff changeset
    73
          ))
b00f5057ca3c Rewrite code to use 'define-derived-mode'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 323
diff changeset
    74
  (use-local-map dict-c5-mode-map)
b00f5057ca3c Rewrite code to use 'define-derived-mode'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 323
diff changeset
    75
  (modify-syntax-entry ?' ".")
b00f5057ca3c Rewrite code to use 'define-derived-mode'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 323
diff changeset
    76
  (modify-syntax-entry ?\" ".")
333
22928defcb53 Prevent wrap '_____' keyword.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 332
diff changeset
    77
  (make-local-variable 'paragraph-separate)
22928defcb53 Prevent wrap '_____' keyword.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 332
diff changeset
    78
  (setq paragraph-separate "\\([ \t\f]*\\|_\\{5,\\}\\)$")
22928defcb53 Prevent wrap '_____' keyword.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 332
diff changeset
    79
  (make-local-variable 'paragraph-start)
22928defcb53 Prevent wrap '_____' keyword.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 332
diff changeset
    80
  (setq paragraph-start paragraph-separate)
325
e64b740278c5 Finally fix multiline highlighting.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 324
diff changeset
    81
  (add-hook 'font-lock-extend-region-functions 'dict-c5-font-lock-extend-region t)
320
4272023569f3 major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    82
  )
4272023569f3 major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    83
4272023569f3 major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    84
;;; dict-mode.el ends here