[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode 9e62157 338/405: (comment-region) and (uncomm
From: |
Stefan Monnier |
Subject: |
[elpa] externals/phps-mode 9e62157 338/405: (comment-region) and (uncomment-region) now handles part of lines as well as full lines |
Date: |
Sat, 13 Jul 2019 10:00:44 -0400 (EDT) |
branch: externals/phps-mode
commit 9e621570a8cd0f70f6465a9cda3c4ab9974264b8
Author: Christian Johansson <address@hidden>
Commit: Christian Johansson <address@hidden>
(comment-region) and (uncomment-region) now handles part of lines as well
as full lines
---
phps-mode-functions.el | 101 +++++++++++++++++++++++++++++---------------
phps-mode-test-functions.el | 14 ++++++
2 files changed, 82 insertions(+), 33 deletions(-)
diff --git a/phps-mode-functions.el b/phps-mode-functions.el
index 0de3711..cbc48a0 100644
--- a/phps-mode-functions.el
+++ b/phps-mode-functions.el
@@ -794,20 +794,36 @@
(goto-char beg)
(let ((end-line-number (line-number-at-pos end t))
- (current-line-number (line-number-at-pos)))
+ (current-line-number (line-number-at-pos))
+ (first-line t))
- ;; Do this for every line in region
- (while (< current-line-number end-line-number)
- (move-beginning-of-line nil)
+ ;; Does region start at beginning of line?
+ (if (not (= beg (line-beginning-position)))
- ;; Does this line contain something other than white-space?
- (unless (eq (point) (line-end-position))
- (insert comment-start)
- (move-end-of-line nil)
- (insert comment-end))
+ ;; Use doc comment
+ (progn
+ (goto-char end)
+ (insert " */")
+ (goto-char beg)
+ (insert "/* "))
- (line-move 1)
- (setq current-line-number (line-number-at-pos))))))
+ ;; Do this for every line in region
+ (while (or first-line
+ (< current-line-number end-line-number))
+ (move-beginning-of-line nil)
+
+ (when first-line
+ (setq first-line nil))
+
+ ;; Does this line contain something other than white-space?
+ (unless (eq (point) (line-end-position))
+ (insert "// ")
+ (move-end-of-line nil)
+ (insert ""))
+
+ (when (< current-line-number end-line-number)
+ (line-move 1))
+ (setq current-line-number (line-number-at-pos)))))))
(defun phps-mode-functions-uncomment-region (beg end &optional _arg)
"Comment region from BEG to END with optional ARG."
@@ -817,28 +833,47 @@
(goto-char beg)
(let ((end-line-number (line-number-at-pos end t))
- (current-line-number (line-number-at-pos)))
-
- ;; Do this for every line in region
- (while (< current-line-number end-line-number)
- (move-beginning-of-line nil)
-
- ;; Does this line contain something other than white-space?
- (unless (>= (+ (point) 3) (line-end-position))
- (when (looking-at-p "\/\/ ")
- (delete-char 3))
- (when (looking-at-p "\/\\* ")
- (delete-char 3))
-
- (move-end-of-line nil)
-
- (backward-char 3)
- (when (looking-at-p " \\*\/")
- (delete-char 3)))
-
- (line-move 1)
- (setq current-line-number (line-number-at-pos))))))
-
+ (current-line-number (line-number-at-pos))
+ (first-line t))
+
+ ;; Does region start at beginning of line?
+ (if (not (= beg (line-beginning-position)))
+ (progn
+ (goto-char end)
+ (backward-char 3)
+ (when (looking-at-p " \\*\/")
+ (delete-char 3))
+
+ (goto-char beg)
+ (when (looking-at-p "\/\/ ")
+ (delete-char 3))
+ (when (looking-at-p "\/\\* ")
+ (delete-char 3)))
+
+ ;; Do this for every line in region
+ (while (or first-line
+ (< current-line-number end-line-number))
+ (move-beginning-of-line nil)
+
+ (when first-line
+ (setq first-line nil))
+
+ ;; Does this line contain something other than white-space?
+ (unless (>= (+ (point) 3) (line-end-position))
+ (when (looking-at-p "\/\/ ")
+ (delete-char 3))
+ (when (looking-at-p "\/\\* ")
+ (delete-char 3))
+
+ (move-end-of-line nil)
+
+ (backward-char 3)
+ (when (looking-at-p " \\*\/")
+ (delete-char 3)))
+
+ (when (< current-line-number end-line-number)
+ (line-move 1))
+ (setq current-line-number (line-number-at-pos)))))))
(defun phps-mode-functions-init ()
"PHP specific init-cleanup routines."
diff --git a/phps-mode-test-functions.el b/phps-mode-test-functions.el
index e146b73..ae9386b 100644
--- a/phps-mode-test-functions.el
+++ b/phps-mode-test-functions.el
@@ -793,12 +793,26 @@
(should (equal buffer-contents "// <?php\n// namespace myNamespace;\n//
class myClass extends myAbstract implements myInterface {\n// public
function myFunctionA($myArg = null) {}\n// protected function
myFunctionB($myArg = 'abc') {}\n// }\n"))))
(phps-mode-test-with-buffer
+ "<?php\nnamespace myNamespace;\nclass myClass extends myAbstract implements
myInterface {\n public function myFunctionA($myArg = null) {}\n protected
function myFunctionB($myArg = 'abc') {}\n}\n"
+ "Comment part of object-oriented file with bracket-less namespace, class
that extends and implements and functions with optional arguments"
+ (comment-region 62 86)
+ (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
+ (should (equal buffer-contents "<?php\nnamespace myNamespace;\nclass
myClass extends myAbstract/* implements myInterface */{\n public function
myFunctionA($myArg = null) {}\n protected function myFunctionB($myArg =
'abc') {}\n}\n"))))
+
+ (phps-mode-test-with-buffer
"// <?php\n// namespace myNamespace;\n// class myClass extends myAbstract
implements myInterface {\n// public function myFunctionA($myArg = null)
{}\n// protected function myFunctionB($myArg = 'abc') {}\n// }\n"
"Uncomment object-oriented file with bracket-less namespace, class that
extends and implements and functions with optional arguments"
(uncomment-region (point-min) (point-max))
(let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
(should (equal buffer-contents "<?php\nnamespace myNamespace;\nclass
myClass extends myAbstract implements myInterface {\n public function
myFunctionA($myArg = null) {}\n protected function myFunctionB($myArg =
'abc') {}\n}\n"))))
+ (phps-mode-test-with-buffer
+ "<?php\nnamespace myNamespace;\nclass myClass extends myAbstract/*
implements myInterface */{\n public function myFunctionA($myArg = null)
{}\n protected function myFunctionB($myArg = 'abc') {}\n}\n"
+ "Uncomment part of object-oriented file with bracket-less namespace, class
that extends and implements and functions with optional arguments"
+ (uncomment-region 62 92)
+ (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
+ (should (equal buffer-contents "<?php\nnamespace myNamespace;\nclass
myClass extends myAbstract implements myInterface {\n public function
myFunctionA($myArg = null) {}\n protected function myFunctionB($myArg =
'abc') {}\n}\n"))))
+
)
(defun phps-mode-test-functions ()
- [elpa] externals/phps-mode a45b39a 339/405: Added two failing indentation tests for concatenated equal assignment and double arrow multi-line array declaration, (continued)
- [elpa] externals/phps-mode a45b39a 339/405: Added two failing indentation tests for concatenated equal assignment and double arrow multi-line array declaration, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 3e1ff06 332/405: Added integration-tests for syntax colouring and update goals, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode ced201d 322/405: Updated syntax colouring for namespace, class, function and constant names, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 8298a6a 325/405: Colorized strings after namespace separator, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode a30e5ff 331/405: Run incremental lexer when processing file if buffer change, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode e9475f7 321/405: Merge branch 'master' of https://github.com/cjohansson/emacs-phps-mode, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 55b3087 333/405: Optimized lexer calling, do not call when using (indent-line), Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode a309998 326/405: Integration tests passes with new function, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode c37b234 334/405: Added failing test for indent in concatenated string inside function arguments, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 8109c1a 328/405: (uncomment-region) working, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 9e62157 338/405: (comment-region) and (uncomment-region) now handles part of lines as well as full lines,
Stefan Monnier <=
- [elpa] externals/phps-mode 091ab21 340/405: Passes new unit test for indentation of concatenated equal and multiplication equal assignments, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode d27af61 327/405: Fixed bug with incremental lexer were states are missing, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 32f9808 329/405: indent and imenu now triggers incremental lexer if buffer changed, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 365d739 324/405: Changed structure of integration tests, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 2807902 343/405: Added syntax coloring for %, =, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 1bac28a 352/405: Updated readme with decreased percent for indent, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 2801604 350/405: Added TODO item, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode c80aa68 351/405: Added a new failing test for indentation of else expression inside switch, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode a8fbe7d 344/405: Improved syntax coloring of =, % and more, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 64e1789 356/405: Fixed indentation were assignments end at next line, Stefan Monnier, 2019/07/13