-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add bracketcolors plugin Color {}, [], () based on nesting order
- Loading branch information
1 parent
2665511
commit d005a26
Showing
17 changed files
with
3,040 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,13 @@ M: Pavel Roschin <rpg89(at)post(dot)ru> | |
W: | ||
S: Maintained | ||
|
||
bracketcolors | ||
* P: Asif Amin <[email protected]> | ||
* g: @asifamin13 | ||
* M: Asif Amin <[email protected]> | ||
* W: | ||
* S: Maintained | ||
|
||
codenav | ||
P: Federico Reghenzani <federico(dot)dev(at)reghe(dot)net> | ||
g: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Asif Amin <[email protected]> |
Large diffs are not rendered by default.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
include $(top_srcdir)/build/vars.auxfiles.mk | ||
|
||
SUBDIRS = src | ||
plugin = bracketcolors |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
Color brackets, parenthesis, and braces | ||
=================== | ||
|
||
.. contents:: | ||
|
||
About | ||
----- | ||
|
||
This plugin enables bracket coloring features. Brackets are colored based on | ||
nesting level | ||
|
||
Features | ||
-------- | ||
|
||
* Color brackets for: { }, [ ], ( ) | ||
|
||
Usage | ||
----- | ||
|
||
Install the plugin (https://plugins.geany.org/install.html) then | ||
load it in Geany's plugin manager. | ||
|
||
Requirements | ||
------------ | ||
|
||
* Geany >= 1.38 | ||
* C++17 | ||
|
||
Contact developers | ||
------------------ | ||
|
||
Asif Amin <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
/* | ||
* BracketMap.cc | ||
* | ||
* Copyright 2013 Asif Amin <[email protected]> | ||
* | ||
* This program 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 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program 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 this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | ||
* MA 02110-1301, USA. | ||
*/ | ||
|
||
#ifdef HAVE_CONFIG_H | ||
# include "config.h" | ||
#endif | ||
|
||
#include <stack> | ||
#include <set> | ||
|
||
#include "BracketMap.h" | ||
|
||
|
||
// ----------------------------------------------------------------------------- | ||
BracketMap::BracketMap() | ||
/* | ||
Constructor | ||
----------------------------------------------------------------------------- */ | ||
{ | ||
|
||
} | ||
|
||
|
||
// ----------------------------------------------------------------------------- | ||
BracketMap::~BracketMap() | ||
/* | ||
Destructor | ||
----------------------------------------------------------------------------- */ | ||
{ | ||
|
||
} | ||
|
||
|
||
// ----------------------------------------------------------------------------- | ||
void BracketMap::Update(Index index, Length length) | ||
/* | ||
----------------------------------------------------------------------------- */ | ||
{ | ||
auto it = mBracketMap.find(index); | ||
if (it != mBracketMap.end()) { | ||
auto &bracket = it->second; | ||
GetLength(bracket) = length; | ||
} | ||
else { | ||
mBracketMap.insert( | ||
std::make_pair(index, std::make_tuple(length, 0)) | ||
); | ||
} | ||
} | ||
|
||
|
||
|
||
// ----------------------------------------------------------------------------- | ||
void BracketMap::ComputeOrder() | ||
/* | ||
----------------------------------------------------------------------------- */ | ||
{ | ||
std::stack<Index> orderStack; | ||
|
||
for (auto &it : mBracketMap) { | ||
|
||
const Index &startIndex = it.first; | ||
Bracket &bracket = it.second; | ||
Length length = GetLength(bracket); | ||
Index endPos = startIndex + length; | ||
|
||
if (length == UNDEFINED) { | ||
// Invalid brackets | ||
GetOrder(bracket) = UNDEFINED; | ||
continue; | ||
} | ||
|
||
|
||
if (orderStack.size() == 0) { | ||
// First bracket | ||
orderStack.push(endPos); | ||
} | ||
else if (startIndex > orderStack.top()) { | ||
// not nested | ||
while(orderStack.size() > 0 and orderStack.top() < startIndex) { | ||
orderStack.pop(); | ||
} | ||
orderStack.push(endPos); | ||
} | ||
else { | ||
// nested bracket | ||
orderStack.push(endPos); | ||
} | ||
|
||
GetOrder(bracket) = orderStack.size() - 1; | ||
} | ||
} | ||
|
||
|
||
|
||
// ----------------------------------------------------------------------------- | ||
void BracketMap::Show() | ||
/* | ||
----------------------------------------------------------------------------- */ | ||
{ g_debug("%s: Showing bracket map ...", __FUNCTION__); | ||
|
||
for (const auto it : mBracketMap) { | ||
|
||
const Index &startIndex = it.first; | ||
const Bracket &bracket = it.second; | ||
|
||
Length length = std::get<0>(bracket); | ||
Order order = std::get<1>(bracket); | ||
|
||
Index end = -1; | ||
if (length > 0) { | ||
end = startIndex + length; | ||
} | ||
|
||
g_debug( | ||
"%s: Bracket at %d, Length: %d, End: %d, Order: %d", | ||
__FUNCTION__, startIndex, length, end, order | ||
); | ||
} | ||
|
||
g_debug("%s: ... Finished showing bracket map", __FUNCTION__); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* BracketMap.h | ||
* | ||
* Copyright 2013 Asif Amin <[email protected]> | ||
* | ||
* This program 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 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program 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 this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | ||
* MA 02110-1301, USA. | ||
*/ | ||
|
||
#ifndef __BRACKET_MAP_H__ | ||
#define __BRACKET_MAP_H__ | ||
|
||
#include <map> | ||
#include <tuple> | ||
|
||
#include <glib.h> | ||
|
||
|
||
// ----------------------------------------------------------------------------- | ||
struct BracketMap | ||
/* | ||
Purpose: data structure which stores and computes nesting order | ||
----------------------------------------------------------------------------- */ | ||
{ | ||
typedef gint Length, Order, Index; | ||
typedef std::tuple<Length, Order> Bracket; | ||
std::map<Index, Bracket> mBracketMap; | ||
|
||
BracketMap(); | ||
~BracketMap(); | ||
|
||
void Show(); | ||
|
||
void Update(Index index, Length length); | ||
void ComputeOrder(); | ||
|
||
static const gint UNDEFINED = -1; | ||
|
||
static Length& GetLength(Bracket &bracket) { | ||
return std::get<0>(bracket); | ||
} | ||
static Order& GetOrder(Bracket &bracket) { | ||
return std::get<1>(bracket); | ||
} | ||
|
||
static const Length& GetLength(const Bracket &bracket) { | ||
return std::get<0>(bracket); | ||
} | ||
static const Order& GetOrder(const Bracket &bracket) { | ||
return std::get<1>(bracket); | ||
} | ||
}; | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
include $(top_srcdir)/build/vars.build.mk | ||
plugin = bracketcolors | ||
|
||
geanyplugins_LTLIBRARIES = bracketcolors.la | ||
|
||
bracketcolors_srcs = \ | ||
bracketcolors.cc \ | ||
BracketMap.cc \ | ||
BracketMap.h | ||
|
||
bracketcolors_la_SOURCES = $(bracketcolors_srcs) | ||
bracketcolors_la_CXXFLAGS = $(AM_CXXFLAGS) $(AM_CFLAGS) -DG_LOG_DOMAIN=\"BracketColors\" | ||
bracketcolors_la_LIBADD = $(COMMONLIBS) | ||
|
||
include $(top_srcdir)/build/cppcheck.mk |
Oops, something went wrong.