Klimi's new dotfiles with stow.
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

123 řádky
4.6 KiB

před 5 roky
  1. ;;; company-xcode.el --- company-mode completion backend for Xcode projects
  2. ;; Copyright (C) 2009-2011, 2014 Free Software Foundation, Inc.
  3. ;; Author: Nikolaj Schumacher
  4. ;; This file is part of GNU Emacs.
  5. ;; GNU Emacs is free software: you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; GNU Emacs is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Commentary:
  16. ;;
  17. ;;; Code:
  18. (require 'company)
  19. (require 'cl-lib)
  20. (defgroup company-xcode nil
  21. "Completion backend for Xcode projects."
  22. :group 'company)
  23. (defcustom company-xcode-xcodeindex-executable (executable-find "xcodeindex")
  24. "Location of xcodeindex executable."
  25. :type 'file)
  26. (defvar company-xcode-tags nil)
  27. (defun company-xcode-reset ()
  28. "Reset the cached tags."
  29. (interactive)
  30. (setq company-xcode-tags nil))
  31. (defcustom company-xcode-types
  32. '("Class" "Constant" "Enum" "Macro" "Modeled Class" "Structure"
  33. "Type" "Union" "Function")
  34. "The types of symbols offered by `company-xcode'.
  35. No context-enabled completion is available. Types like methods will be
  36. offered regardless of whether the class supports them. The defaults should be
  37. valid in most contexts."
  38. :set (lambda (variable value)
  39. (set variable value)
  40. (company-xcode-reset))
  41. :type '(set (const "Category") (const "Class") (const "Class Method")
  42. (const "Class Variable") (const "Constant") (const "Enum")
  43. (const "Field") (const "Instance Method")
  44. (const "Instance Variable") (const "Macro")
  45. (const "Modeled Class") (const "Modeled Method")
  46. (const "Modeled Property") (const "Property") (const "Protocol")
  47. (const "Structure") (const "Type") (const "Union")
  48. (const "Variable") (const "Function")))
  49. (defvar-local company-xcode-project 'unknown)
  50. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  51. (defun company-xcode-fetch (project-bundle)
  52. (setq project-bundle (directory-file-name project-bundle))
  53. (message "Retrieving dump from %s..." project-bundle)
  54. (with-temp-buffer
  55. (let ((default-directory (file-name-directory project-bundle)))
  56. (call-process company-xcode-xcodeindex-executable nil (current-buffer)
  57. nil "dump" "-project"
  58. (file-name-nondirectory project-bundle) "-quiet")
  59. (goto-char (point-min))
  60. (let ((regexp (concat "^\\([^\t\n]*\\)\t[^\t\n]*\t"
  61. (regexp-opt company-xcode-types)
  62. "\t[^\t\n]*\t[^\t\n]*"))
  63. candidates)
  64. (while (re-search-forward regexp nil t)
  65. (cl-pushnew (match-string 1) candidates :test #'equal))
  66. (message "Retrieving dump from %s...done" project-bundle)
  67. candidates))))
  68. (defun company-xcode-find-project ()
  69. (let ((dir (if buffer-file-name
  70. (file-name-directory buffer-file-name)
  71. (expand-file-name default-directory)))
  72. (prev-dir nil)
  73. file)
  74. (while (not (or file (equal dir prev-dir)))
  75. (setq file (car (directory-files dir t ".xcodeproj\\'" t))
  76. prev-dir dir
  77. dir (file-name-directory (directory-file-name dir))))
  78. file))
  79. (defun company-xcode-tags ()
  80. (when (eq company-xcode-project 'unknown)
  81. (setq company-xcode-project (company-xcode-find-project)))
  82. (when company-xcode-project
  83. (cdr (or (assoc company-xcode-project company-xcode-tags)
  84. (car (push (cons company-xcode-project
  85. (company-xcode-fetch company-xcode-project))
  86. company-xcode-tags))))))
  87. ;;;###autoload
  88. (defun company-xcode (command &optional arg &rest ignored)
  89. "`company-mode' completion backend for Xcode projects."
  90. (interactive (list 'interactive))
  91. (cl-case command
  92. (interactive (company-begin-backend 'company-xcode))
  93. (prefix (and company-xcode-xcodeindex-executable
  94. (company-xcode-tags)
  95. (not (company-in-string-or-comment))
  96. (or (company-grab-symbol) 'stop)))
  97. (candidates (let ((completion-ignore-case nil))
  98. (company-xcode-tags)
  99. (all-completions arg (company-xcode-tags))))))
  100. (provide 'company-xcode)
  101. ;;; company-xcode.el ends here