-
Notifications
You must be signed in to change notification settings - Fork 282
Add bracket colors plugin #1221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
asifamin13
wants to merge
3
commits into
geany:master
Choose a base branch
from
asifamin13:bracketcolors_v1
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 <asifamin@utexas.edu> |
Large diffs are not rendered by default.
Oops, something went wrong.
Empty file.
This file contains hidden or 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 hidden or 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, often referred as "rainbow brackets". | ||
|
|
||
| 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 <asifamin@utexas.edu> |
This file contains hidden or 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,119 @@ | ||
| /* | ||
| * BracketMap.cc | ||
| * | ||
| * Copyright 2023 Asif Amin <asifamin@utexas.edu> | ||
| * | ||
| * 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)) | ||
| ); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| // ----------------------------------------------------------------------------- | ||
| std::set<BracketMap::Index> BracketMap::ComputeOrder() | ||
| /* | ||
|
|
||
| ----------------------------------------------------------------------------- */ | ||
| { | ||
| std::stack<Index> orderStack; | ||
| std::set<Index> updatedBrackets; | ||
|
|
||
| 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); | ||
| } | ||
|
|
||
| Order newOrder = orderStack.size() - 1; | ||
| Order currOrder = GetOrder(bracket); | ||
| if (newOrder != currOrder) { | ||
| updatedBrackets.insert(startIndex); | ||
| } | ||
|
|
||
| GetOrder(bracket) = newOrder; | ||
| } | ||
|
|
||
| return updatedBrackets; | ||
| } |
This file contains hidden or 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,64 @@ | ||
| /* | ||
| * BracketMap.h | ||
| * | ||
| * Copyright 2023 Asif Amin <asifamin@utexas.edu> | ||
| * | ||
| * 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 <set> | ||
|
|
||
| #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 Update(Index index, Length length); | ||
| std::set<Index> 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 | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.