[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 0afe18d 09/66: Allow CMake completion in strings when insi
From: |
Dmitry Gutov |
Subject: |
[elpa] master 0afe18d 09/66: Allow CMake completion in strings when inside ${...} |
Date: |
Mon, 5 Nov 2018 18:19:13 -0500 (EST) |
branch: master
commit 0afe18da1f7a4c25f3474e0c040dd56003453047
Author: Zuogon Yue <address@hidden>
Commit: Dmitry Gutov <address@hidden>
Allow CMake completion in strings when inside ${...}
---
company-cmake.el | 26 +++++++++++++++++++++++++-
test/cmake-tests.el | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 77 insertions(+), 1 deletion(-)
diff --git a/company-cmake.el b/company-cmake.el
index 010df32..6d29622 100644
--- a/company-cmake.el
+++ b/company-cmake.el
@@ -177,6 +177,29 @@ They affect which types of symbols we get completion
candidates for.")
(buffer-substring-no-properties (line-beginning-position)
(point-max))))))
+(defun company-cmake-prefix-dollar-brace-p ()
+ "Test if the current char is prefix with ${ in the current line."
+ (let ((position-current (point))
+ (position-beg-of-line (line-beginning-position))
+ (position-end-of-line (line-end-position))
+ (position-matched nil)
+ (position-matched-right-brace nil))
+
+ (setq position-matched
+ (re-search-backward "\$\{" position-beg-of-line t))
+ (goto-char position-current)
+ (setq position-matched-right-brace
+ (re-search-backward "\}" position-beg-of-line t))
+ (goto-char position-current)
+
+ (if (or (and position-matched
+ position-matched-right-brace
+ (> position-matched position-matched-right-brace))
+ (and position-matched
+ (not position-matched-right-brace)))
+ t
+ nil)))
+
(defun company-cmake (command &optional arg &rest ignored)
"`company-mode' completion backend for CMake.
CMake is a cross-platform, open-source make system."
@@ -187,7 +210,8 @@ CMake is a cross-platform, open-source make system."
(unless company-cmake-executable
(error "Company found no cmake executable"))))
(prefix (and (memq major-mode company-cmake-modes)
- (not (company-in-string-or-comment))
+ (or (not (company-in-string-or-comment))
+ (company-cmake-prefix-dollar-brace-p))
(company-grab-symbol)))
(candidates (company-cmake--candidates arg))
(meta (company-cmake--meta arg))
diff --git a/test/cmake-tests.el b/test/cmake-tests.el
new file mode 100644
index 0000000..805ea1a
--- /dev/null
+++ b/test/cmake-tests.el
@@ -0,0 +1,52 @@
+;;; cmake-tests.el --- company-mode tests -*- lexical-binding: t -*-
+
+;; Copyright (C) 2017 Free Software Foundation, Inc.
+
+;; Author: Zuogong Yue
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs 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.
+
+;; GNU Emacs 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. If not, see <http://www.gnu.org/licenses/>.
+
+(require 'company-tests)
+(require 'company-cmake)
+
+(ert-deftest company-cmake-complete-in-string-prefix-quotes ()
+ (with-temp-buffer
+ (insert "set(MyFlags \"${CMAKE_CXX_FLAGS_R")
+ (setq-local major-mode 'cmake-mode)
+ (should (equal (company-cmake 'prefix)
+ "CMAKE_CXX_FLAGS_R"))))
+
+(ert-deftest company-cmake-complete-in-string-between-quotes ()
+ (with-temp-buffer
+ (insert "set(MyFlags \"${CMAKE_CXX_FLAGS_R}\"")
+ (backward-char 2)
+ (setq-local major-mode 'cmake-mode)
+ (should (equal (company-cmake 'prefix)
+ "CMAKE_CXX_FLAGS_R"))))
+
+(ert-deftest company-cmake-complete-in-string-more-prefix ()
+ (with-temp-buffer
+ (insert "set(MyFlags \"${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_R")
+ (setq-local major-mode 'cmake-mode)
+ (should (equal (company-cmake 'prefix)
+ "CMAKE_CXX_FLAGS_R"))))
+
+(ert-deftest company-cmake-complete-in-string-more-prefix-2 ()
+ (with-temp-buffer
+ (insert "set(MyFlags \"${CMAKE_CXX_FLAGS} CMAKE_CXX_FLAGS_R")
+ (setq-local major-mode 'cmake-mode)
+ (should (equal (company-cmake 'prefix)
+ nil))))
\ No newline at end of file
- [elpa] master updated (ff13541 -> 1e22493), Dmitry Gutov, 2018/11/05
- [elpa] master 4a4152b 02/66: Add a FIXME, Dmitry Gutov, 2018/11/05
- [elpa] master e72dfad 03/66: copyright-update, Dmitry Gutov, 2018/11/05
- [elpa] master 2a21bfd 01/66: Extract company--capf-post-completion, for easier debugging, Dmitry Gutov, 2018/11/05
- [elpa] master 0dc6945 08/66: Fix the build, Dmitry Gutov, 2018/11/05
- [elpa] master fc81e99 04/66: Deprecate company-css, Dmitry Gutov, 2018/11/05
- [elpa] master 1646a10 16/66: Always get candidates with prefix string in `company-diag`., Dmitry Gutov, 2018/11/05
- [elpa] master 07c56b1 12/66: Add NEWS entry, Dmitry Gutov, 2018/11/05
- [elpa] master 0afe18d 09/66: Allow CMake completion in strings when inside ${...},
Dmitry Gutov <=
- [elpa] master 67650de 17/66: Merge pull request #769 from tigersoldier/master, Dmitry Gutov, 2018/11/05
- [elpa] master 23e6c82 07/66: Add NEWS entry, Dmitry Gutov, 2018/11/05
- [elpa] master 5c2425b 06/66: Work around python-shell-completion-at-point's behavior, Dmitry Gutov, 2018/11/05
- [elpa] master a64d52c 05/66: Deprecate company-nxml too, Dmitry Gutov, 2018/11/05
- [elpa] master 5698be9 10/66: Simplify company-cmake-prefix-dollar-brace-p, Dmitry Gutov, 2018/11/05
- [elpa] master 5118b59 14/66: company-tng: Supress post-completion (#731), Dmitry Gutov, 2018/11/05
- [elpa] master a78f7d8 15/66: Merge pull request #764 from nikital/tng-supress-post-completion, Dmitry Gutov, 2018/11/05
- [elpa] master 5a856d7 13/66: backend: Remove pre-completion command, Dmitry Gutov, 2018/11/05
- [elpa] master 5b11709 31/66: Emacs 24 doesn't have working elisp capf, so don't test it, Dmitry Gutov, 2018/11/05
- [elpa] master b0940fb 29/66: Close #798: look for :company-match function in the capf's metadata, Dmitry Gutov, 2018/11/05