company-oddmuse.el (2069B)
1 ;;; company-oddmuse.el --- company-mode completion backend for oddmuse-mode 2 3 ;; Copyright (C) 2009-2011, 2013-2016, 2022 Free Software Foundation, Inc. 4 5 ;; Author: Nikolaj Schumacher 6 7 ;; This file is part of GNU Emacs. 8 9 ;; GNU Emacs is free software: you can redistribute it and/or modify 10 ;; it under the terms of the GNU General Public License as published by 11 ;; the Free Software Foundation, either version 3 of the License, or 12 ;; (at your option) any later version. 13 14 ;; GNU Emacs is distributed in the hope that it will be useful, 15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 ;; GNU General Public License for more details. 18 19 ;; You should have received a copy of the GNU General Public License 20 ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. 21 22 23 ;;; Commentary: 24 ;; 25 26 ;;; Code: 27 28 (require 'company) 29 (require 'cl-lib) 30 (eval-when-compile (require 'yaoddmuse nil t)) 31 (eval-when-compile (require 'oddmuse nil t)) 32 33 (defvar company-oddmuse-link-regexp 34 "\\(\\<[A-Z][[:alnum:]]*\\>\\)\\|\\[\\[\\([[:alnum:]]+\\>\\|\\)") 35 36 (defun company-oddmuse-get-page-table () 37 (cl-case major-mode 38 (yaoddmuse-mode (with-no-warnings 39 (yaoddmuse-get-pagename-table yaoddmuse-wikiname))) 40 (oddmuse-mode (with-no-warnings 41 (oddmuse-make-completion-table oddmuse-wiki))))) 42 43 ;;;###autoload 44 (defun company-oddmuse (command &optional arg &rest ignored) 45 "`company-mode' completion backend for `oddmuse-mode'." 46 (interactive (list 'interactive)) 47 (cl-case command 48 (interactive (company-begin-backend 'company-oddmuse)) 49 (prefix (let ((case-fold-search nil)) 50 (and (memq major-mode '(oddmuse-mode yaoddmuse-mode)) 51 (looking-back company-oddmuse-link-regexp (line-beginning-position)) 52 (or (match-string 1) 53 (match-string 2))))) 54 (candidates (all-completions arg (company-oddmuse-get-page-table))))) 55 56 (provide 'company-oddmuse) 57 ;;; company-oddmuse.el ends here