emacs-elpa-diffs
[Top][All Lists]
Advanced

[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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]