profile
viewpoint
Holger Rapp SirVer Qwello Germany http://www.sirver.net OSS founder: Widelands, UltiSnip. Ex-Googler, did OSS there (Cartographer). Founded Lyft's first international office. Now CTO of Qwello.eu.

honza/vim-snippets 4077

vim-snipmate default snippets (Previously snipmate-snippets)

SirVer/move_window 58

Tool to arange windows quickly on the Mac OS X desktop

SirVer/cagd5e 32

My sample code and solutions to some programming exercises for the book "Curves and Surfaces for CAGD" by Gerald Farin

SirVer/edu_trees 4

Eductational implementations of some Tree data structures in Python

SirVer/cartographer_ros 1

Provides ROS integration for Cartographer.

SirVer/homebrew 1

The missing package manager for OS X.

SirVer/ack.vim 0

Plugin for the Perl module / CLI script 'ack'

SirVer/android_core 0

Android libraries for rosjava

SirVer/cartographer 0

Cartographer is a system that provides real-time simultaneous localization and mapping (SLAM) in 2D and 3D across multiple platforms and sensor configurations.

SirVer/cartographer_fetch 0

Provides Fetch integration for Cartographer.

pull request commentSirVer/ultisnips

[WIP] tiebreaker fix

@hl037 I think you can merge master into this and we can start reviewing it. Wdyt?

hl037

comment created time in 7 days

issue commentSirVer/ultisnips

Ultisnip keep display error while typing

Looking through the longer traceback, what jumps out to me is

ModuleNotFoundError: No module named 'msvcrt'

This does not seem to be an UltiSnips issue, it is very likely something is broken with your Python installation or at least with the python that is used within your Vim. Very hard to debug from here.... But I am nearly certain that this is not ultisnips specific, it is just triggered by UltiSnips.

duytrung

comment created time in 7 days

PullRequestReviewEvent

issue commentSirVer/ultisnips

Ideas for a future major version

if it is a third-party helper we will need to vendor it into UltiSnips though (which is fine from my point of view), because dealing with python dependencies in a plugin for Vim is a nightmare.

hl037

comment created time in 7 days

issue commentSirVer/ultisnips

Is it possible to set a context for all snippets in a file?

I tend to say it is not worth it. It also adds complexity: there is more state to keep track of when reading a snippet file. There is already a piece of state which is the priority (and in some sense global), so this is not really adding something entirely new, but the semantics of a snippet would now also depend on a global state, which makes them harder to digest.

I am on the fence about this though.

owd2

comment created time in 7 days

issue commentSirVer/ultisnips

Is it possible to set a context for all snippets in a file?

I also feel that context handling should be on the editor, not the snippet engine. Other editors do this much better than Vim, for example Sublime or TextMate did not have the idea of a "filetype", instead all configuration was on the context level. Context could be nested, so if you were for example in a python text snippet within a markdown file, all of your python shortcuts, snippets and commands were available. Much better design.

I do not know if any modern editor did repeat this, but for sure Vim did not. Adding it through a plugin is a tad overkill in my opinion.

owd2

comment created time in 8 days

issue closedSirVer/ultisnips

Python interpolation not working?

<!-- Thanks for reporting your issue. Please follow this template closely. Without all essential info the issue may be closed as unreproducible.

Fill out the table below ----- symbols and keep it at the end of your issue text. Please provide an answer for every line.

Please provide an explanation of the issue below this line. -->

Expected behavior:

Python interpolation should return the comment string.

Actual behavior:

It does not.

Steps to reproduce

Given the following definition:

global !p
def get_commentstring():
    import vim
    s = vim.eval("&commentstring")
    s = s.replace("%s", "")
    return s
endglobal

snippet {1 "Fold 1"
`!v split(&l:commentstring, '%s')[0]`${1}{{{1
${VISUAL}
`!p get_commentstring()`}}}1$1
$0
endsnippet

I get the following expansion:

// {{{1
}}}1

For some reason, the Python return value is not used.

Same obtains with even simpler Python, e.g.:

def get_commentstring():
    return "//"

<!-- NOTE: contents inside arrows will be ignored. -->

  • Operating System: Ubuntu 21.04
  • Vim Version:
    • VIM - Vi IMproved 8.1 (2018 May 18, compiled Nov 08 2021 14:21:34) Included patches: 1-2269
    • NVIM v0.5.1
  • UltiSnips Version: 2c83e40ce66814bf813457bb58ea96184ab9bb81
  • Python inside Vim:
    • :py import sys; print(sys.version)`: not found
    • :py3 import sys; print(sys.version)': 3.8.10 (default, Sep 28 2021, 16:10:42)

closed time in 11 days

jeetsukumaran

issue commentSirVer/ultisnips

Python interpolation not working?

!p get_commentstring() should be !p snip.rv = get_commentstring()

jeetsukumaran

comment created time in 11 days

PullRequestReviewEvent
PullRequestReviewEvent

Pull request review commentwidelands/widelands

Replace `boost::signals2`

 enum class SubscriberPosition { kFront, kBack }; template <typename... Args> class Signal { public: 	/** Wrapper around a callback function. */-	struct SignalSubscriber {-		explicit SignalSubscriber(const Signal& p, const std::function<void(Args...)>& c)-		   : parent_(p), callback_(c) {+	class SignalSubscriber {+	public:+		explicit SignalSubscriber(const Signal& p, const std::function<void(Args...)> c)

isn't explicit meaningless for multi argument constructors?

Noordfrees

comment created time in 12 days

Pull request review commentwidelands/widelands

Replace `boost::signals2`

+/*+ * Copyright (C) 2021 by the Widelands Development Team+ *+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.+ *+ */++#ifndef WL_NOTIFICATIONS_SIGNAL_H+#define WL_NOTIFICATIONS_SIGNAL_H++#include <cassert>+#include <functional>+#include <list>+#include <memory>+#include <set>++#include "base/macros.h"+#include "base/wexception.h"++namespace Notifications {++/** Class that allows attaching callback functions to an object. */+template <typename... Args> class Signal {+public:+	/** Wrapper around a callback function. */+	struct SignalSubscriber {+		explicit SignalSubscriber(const Signal& p, const std::function<void(Args...)>& c)+		   : parent_(p), callback_(c) {+		}+		~SignalSubscriber() {+			parent_.unsubscribe(this);+		}++		const Signal& parent_;+		const std::function<void(Args...)> callback_;++		DISALLOW_COPY_AND_ASSIGN(SignalSubscriber);+	};++	/** Invoke all the signal's subscribers' callback functions. */+	void operator()(Args... args) const {+		for (const auto& s : all_subscribers_) {+			s->callback_(args...);+		}+	}++	/** Create a subscriber with a user-defined lifetime. */+	std::unique_ptr<SignalSubscriber> subscribe(const std::function<void(Args...)>& callback,+	                                            bool at_front = false) const {+		SignalSubscriber* s = new SignalSubscriber(*this, callback);+		if (at_front) {+			all_subscribers_.push_front(s);+		} else {+			all_subscribers_.push_back(s);+		}+		return std::unique_ptr<SignalSubscriber>(s);+	}++	/** Create a subscriber with the same lifetime as the signal. */+	inline void connect(const std::function<void(Args...)>& callback, bool at_front = false) const {+		owned_subscribers_.insert(subscribe(callback, at_front));+	}++	/** Create a subscriber that echoes the signal's invokations to another signal. */+	inline std::unique_ptr<SignalSubscriber> subscribe(const Signal& s,+	                                                   bool at_front = false) const {+		return subscribe([&s](Args... args) { s(args...); }, at_front);+	}+	inline void connect(const Signal& s, bool at_front = false) const {+		connect([&s](Args... args) { s(args...); }, at_front);+	}++	/** Called by a subscriber at the end of its lifetime. */+	void unsubscribe(const SignalSubscriber* s) const {+		for (auto it = all_subscribers_.begin(); it != all_subscribers_.end(); ++it) {+			if (*it == s) {+				all_subscribers_.erase(it);+				return;+			}+		}+		NEVER_HERE();+	}++	Signal() = default;+	~Signal() {+		owned_subscribers_.clear();+		// Any subscribers not owned by us should have been destroyed by their owner by now+		assert(all_subscribers_.empty());+	}++private:+	mutable std::set<std::unique_ptr<SignalSubscriber>> owned_subscribers_;

no, I think mutable is better than a static here. In general I also agree with your thoughts about mutable, especially here not allowing it and avoiding const casts would have a large ripple effect through the code base. I just ask for a comment to explain.

Noordfrees

comment created time in 12 days

PullRequestReviewEvent

Pull request review commentwidelands/widelands

Replace `boost::signals2`

+/*+ * Copyright (C) 2021 by the Widelands Development Team+ *+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.+ *+ */++#ifndef WL_NOTIFICATIONS_SIGNAL_H+#define WL_NOTIFICATIONS_SIGNAL_H++#include <cassert>+#include <functional>+#include <list>+#include <memory>+#include <set>++#include "base/macros.h"+#include "base/wexception.h"++namespace Notifications {++/**+ * Whether a new subscriber will be the last (default)+ * or first to be invoked when the signal is triggered.+ */+enum class SubscriberPosition { kFront, kBack };++/** Class that allows attaching callback functions to an object. */+template <typename... Args> class Signal {+public:+	/** Wrapper around a callback function. */+	struct SignalSubscriber {+		explicit SignalSubscriber(const Signal& p, const std::function<void(Args...)>& c)+		   : parent_(p), callback_(c) {+		}+		~SignalSubscriber() {+			parent_.unsubscribe(this);+		}++		const Signal& parent_;+		const std::function<void(Args...)> callback_;++		DISALLOW_COPY_AND_ASSIGN(SignalSubscriber);+	};++	/** Invoke all the signal's subscribers' callback functions. */+	void operator()(Args... args) const {+		for (const auto& s : all_subscribers_) {+			s->callback_(args...);+		}+	}++	/** Create a subscriber with a user-defined lifetime. */+	std::unique_ptr<SignalSubscriber>+	subscribe(const std::function<void(Args...)>& callback,+	          SubscriberPosition pos = SubscriberPosition::kBack) const {+		SignalSubscriber* s = new SignalSubscriber(*this, callback);+		switch (pos) {+		case SubscriberPosition::kBack:+			all_subscribers_.push_back(s);+			break;+		case SubscriberPosition::kFront:+			all_subscribers_.push_front(s);+			break;+		}+		return std::unique_ptr<SignalSubscriber>(s);+	}++	/** Create a subscriber with the same lifetime as the signal. */+	inline void connect(const std::function<void(Args...)>& callback,+	                    SubscriberPosition pos = SubscriberPosition::kBack) const {+		owned_subscribers_.insert(subscribe(callback, pos));+	}++	/** Create a subscriber that echoes the signal's invokations to another signal. */+	inline std::unique_ptr<SignalSubscriber>+	subscribe(const Signal& s, SubscriberPosition pos = SubscriberPosition::kBack) const {+		return subscribe([&s](Args... args) { s(args...); }, pos);+	}+	inline void connect(const Signal& s, SubscriberPosition pos = SubscriberPosition::kBack) const {+		connect([&s](Args... args) { s(args...); }, pos);+	}++	/** Called by a subscriber at the end of its lifetime. */+	void unsubscribe(const SignalSubscriber* s) const {

Since this is not public API you could make this private and make the SignalSubscriber a friend of this class.

Noordfrees

comment created time in 13 days

Pull request review commentwidelands/widelands

Replace `boost::signals2`

+/*+ * Copyright (C) 2021 by the Widelands Development Team+ *+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.+ *+ */++#ifndef WL_NOTIFICATIONS_SIGNAL_H+#define WL_NOTIFICATIONS_SIGNAL_H++#include <cassert>+#include <functional>+#include <list>+#include <memory>+#include <set>++#include "base/macros.h"+#include "base/wexception.h"++namespace Notifications {++/**+ * Whether a new subscriber will be the last (default)+ * or first to be invoked when the signal is triggered.+ */+enum class SubscriberPosition { kFront, kBack };++/** Class that allows attaching callback functions to an object. */+template <typename... Args> class Signal {+public:+	/** Wrapper around a callback function. */+	struct SignalSubscriber {+		explicit SignalSubscriber(const Signal& p, const std::function<void(Args...)>& c)+		   : parent_(p), callback_(c) {+		}+		~SignalSubscriber() {+			parent_.unsubscribe(this);+		}++		const Signal& parent_;+		const std::function<void(Args...)> callback_;++		DISALLOW_COPY_AND_ASSIGN(SignalSubscriber);+	};++	/** Invoke all the signal's subscribers' callback functions. */+	void operator()(Args... args) const {+		for (const auto& s : all_subscribers_) {+			s->callback_(args...);+		}+	}++	/** Create a subscriber with a user-defined lifetime. */+	std::unique_ptr<SignalSubscriber>+	subscribe(const std::function<void(Args...)>& callback,+	          SubscriberPosition pos = SubscriberPosition::kBack) const {+		SignalSubscriber* s = new SignalSubscriber(*this, callback);+		switch (pos) {+		case SubscriberPosition::kBack:+			all_subscribers_.push_back(s);+			break;+		case SubscriberPosition::kFront:+			all_subscribers_.push_front(s);+			break;+		}+		return std::unique_ptr<SignalSubscriber>(s);+	}++	/** Create a subscriber with the same lifetime as the signal. */+	inline void connect(const std::function<void(Args...)>& callback,+	                    SubscriberPosition pos = SubscriberPosition::kBack) const {+		owned_subscribers_.insert(subscribe(callback, pos));+	}++	/** Create a subscriber that echoes the signal's invokations to another signal. */

I do not understand this comment. What does echo mean? How do you avoid cycles?

Noordfrees

comment created time in 13 days

Pull request review commentwidelands/widelands

Replace `boost::signals2`

+/*+ * Copyright (C) 2021 by the Widelands Development Team+ *+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.+ *+ */++#ifndef WL_NOTIFICATIONS_SIGNAL_H+#define WL_NOTIFICATIONS_SIGNAL_H++#include <cassert>+#include <functional>+#include <list>+#include <memory>+#include <set>++#include "base/macros.h"+#include "base/wexception.h"++namespace Notifications {++/**+ * Whether a new subscriber will be the last (default)+ * or first to be invoked when the signal is triggered.+ */+enum class SubscriberPosition { kFront, kBack };++/** Class that allows attaching callback functions to an object. */+template <typename... Args> class Signal {+public:+	/** Wrapper around a callback function. */+	struct SignalSubscriber {+		explicit SignalSubscriber(const Signal& p, const std::function<void(Args...)>& c)+		   : parent_(p), callback_(c) {+		}+		~SignalSubscriber() {+			parent_.unsubscribe(this);+		}++		const Signal& parent_;+		const std::function<void(Args...)> callback_;++		DISALLOW_COPY_AND_ASSIGN(SignalSubscriber);+	};++	/** Invoke all the signal's subscribers' callback functions. */+	void operator()(Args... args) const {+		for (const auto& s : all_subscribers_) {+			s->callback_(args...);+		}+	}++	/** Create a subscriber with a user-defined lifetime. */+	std::unique_ptr<SignalSubscriber>+	subscribe(const std::function<void(Args...)>& callback,+	          SubscriberPosition pos = SubscriberPosition::kBack) const {+		SignalSubscriber* s = new SignalSubscriber(*this, callback);+		switch (pos) {+		case SubscriberPosition::kBack:+			all_subscribers_.push_back(s);+			break;+		case SubscriberPosition::kFront:+			all_subscribers_.push_front(s);+			break;+		}+		return std::unique_ptr<SignalSubscriber>(s);+	}++	/** Create a subscriber with the same lifetime as the signal. */+	inline void connect(const std::function<void(Args...)>& callback,

same here about passing by value

Noordfrees

comment created time in 13 days

Pull request review commentwidelands/widelands

Replace `boost::signals2`

+/*+ * Copyright (C) 2021 by the Widelands Development Team+ *+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.+ *+ */++#ifndef WL_NOTIFICATIONS_SIGNAL_H+#define WL_NOTIFICATIONS_SIGNAL_H++#include <cassert>+#include <functional>+#include <list>+#include <memory>+#include <set>++#include "base/macros.h"+#include "base/wexception.h"++namespace Notifications {++/**+ * Whether a new subscriber will be the last (default)+ * or first to be invoked when the signal is triggered.+ */+enum class SubscriberPosition { kFront, kBack };++/** Class that allows attaching callback functions to an object. */+template <typename... Args> class Signal {+public:+	/** Wrapper around a callback function. */+	struct SignalSubscriber {+		explicit SignalSubscriber(const Signal& p, const std::function<void(Args...)>& c)+		   : parent_(p), callback_(c) {+		}+		~SignalSubscriber() {+			parent_.unsubscribe(this);+		}++		const Signal& parent_;+		const std::function<void(Args...)> callback_;++		DISALLOW_COPY_AND_ASSIGN(SignalSubscriber);+	};++	/** Invoke all the signal's subscribers' callback functions. */+	void operator()(Args... args) const {+		for (const auto& s : all_subscribers_) {+			s->callback_(args...);+		}+	}++	/** Create a subscriber with a user-defined lifetime. */+	std::unique_ptr<SignalSubscriber>+	subscribe(const std::function<void(Args...)>& callback,+	          SubscriberPosition pos = SubscriberPosition::kBack) const {+		SignalSubscriber* s = new SignalSubscriber(*this, callback);+		switch (pos) {+		case SubscriberPosition::kBack:+			all_subscribers_.push_back(s);+			break;+		case SubscriberPosition::kFront:+			all_subscribers_.push_front(s);+			break;+		}+		return std::unique_ptr<SignalSubscriber>(s);+	}++	/** Create a subscriber with the same lifetime as the signal. */+	inline void connect(const std::function<void(Args...)>& callback,+	                    SubscriberPosition pos = SubscriberPosition::kBack) const {+		owned_subscribers_.insert(subscribe(callback, pos));+	}++	/** Create a subscriber that echoes the signal's invokations to another signal. */

This function seems to assume that the other signal outlives this signal. This should be mentioned in the comments

Noordfrees

comment created time in 13 days

Pull request review commentwidelands/widelands

Replace `boost::signals2`

+/*+ * Copyright (C) 2021 by the Widelands Development Team+ *+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.+ *+ */++#ifndef WL_NOTIFICATIONS_SIGNAL_H+#define WL_NOTIFICATIONS_SIGNAL_H++#include <cassert>+#include <functional>+#include <list>+#include <memory>+#include <set>++#include "base/macros.h"+#include "base/wexception.h"++namespace Notifications {

I might remember incorrectly, but weren't namespaces lowercase in the Widelands code base?

Noordfrees

comment created time in 13 days

Pull request review commentwidelands/widelands

Replace `boost::signals2`

+/*+ * Copyright (C) 2021 by the Widelands Development Team+ *+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.+ *+ */++#ifndef WL_NOTIFICATIONS_SIGNAL_H+#define WL_NOTIFICATIONS_SIGNAL_H++#include <cassert>+#include <functional>+#include <list>+#include <memory>+#include <set>++#include "base/macros.h"+#include "base/wexception.h"++namespace Notifications {++/**+ * Whether a new subscriber will be the last (default)+ * or first to be invoked when the signal is triggered.+ */+enum class SubscriberPosition { kFront, kBack };++/** Class that allows attaching callback functions to an object. */+template <typename... Args> class Signal {+public:+	/** Wrapper around a callback function. */+	struct SignalSubscriber {+		explicit SignalSubscriber(const Signal& p, const std::function<void(Args...)>& c)+		   : parent_(p), callback_(c) {+		}+		~SignalSubscriber() {+			parent_.unsubscribe(this);+		}++		const Signal& parent_;+		const std::function<void(Args...)> callback_;++		DISALLOW_COPY_AND_ASSIGN(SignalSubscriber);+	};++	/** Invoke all the signal's subscribers' callback functions. */+	void operator()(Args... args) const {+		for (const auto& s : all_subscribers_) {+			s->callback_(args...);+		}+	}++	/** Create a subscriber with a user-defined lifetime. */+	std::unique_ptr<SignalSubscriber>+	subscribe(const std::function<void(Args...)>& callback,

pass std::function by value, it is usually a better choice: https://stackoverflow.com/questions/18365532/should-i-pass-an-stdfunction-by-const-reference#:~:text=If%20there%20is%20any%20possibility,as%20efficient%20as%20a%20const%26%20.

Noordfrees

comment created time in 13 days

PullRequestReviewEvent
PullRequestReviewEvent

Pull request review commentwidelands/widelands

Replace `boost::signals2`

+/*+ * Copyright (C) 2021 by the Widelands Development Team+ *+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.+ *+ */++#ifndef WL_NOTIFICATIONS_SIGNAL_H+#define WL_NOTIFICATIONS_SIGNAL_H++#include <cassert>+#include <functional>+#include <list>+#include <memory>+#include <set>++#include "base/macros.h"+#include "base/wexception.h"++namespace Notifications {++/** Class that allows attaching callback functions to an object. */+template <typename... Args> class Signal {+public:+	/** Wrapper around a callback function. */+	struct SignalSubscriber {+		explicit SignalSubscriber(const Signal& p, const std::function<void(Args...)>& c)+		   : parent_(p), callback_(c) {+		}+		~SignalSubscriber() {+			parent_.unsubscribe(this);+		}++		const Signal& parent_;+		const std::function<void(Args...)> callback_;++		DISALLOW_COPY_AND_ASSIGN(SignalSubscriber);+	};++	/** Invoke all the signal's subscribers' callback functions. */+	void operator()(Args... args) const {+		for (const auto& s : all_subscribers_) {+			s->callback_(args...);+		}+	}++	/** Create a subscriber with a user-defined lifetime. */+	std::unique_ptr<SignalSubscriber> subscribe(const std::function<void(Args...)>& callback,+	                                            bool at_front = false) const {+		SignalSubscriber* s = new SignalSubscriber(*this, callback);+		if (at_front) {+			all_subscribers_.push_front(s);+		} else {+			all_subscribers_.push_back(s);+		}+		return std::unique_ptr<SignalSubscriber>(s);+	}++	/** Create a subscriber with the same lifetime as the signal. */+	inline void connect(const std::function<void(Args...)>& callback, bool at_front = false) const {+		owned_subscribers_.insert(subscribe(callback, at_front));+	}++	/** Create a subscriber that echoes the signal's invokations to another signal. */+	inline std::unique_ptr<SignalSubscriber> subscribe(const Signal& s,+	                                                   bool at_front = false) const {+		return subscribe([&s](Args... args) { s(args...); }, at_front);+	}+	inline void connect(const Signal& s, bool at_front = false) const {+		connect([&s](Args... args) { s(args...); }, at_front);+	}++	/** Called by a subscriber at the end of its lifetime. */+	void unsubscribe(const SignalSubscriber* s) const {+		for (auto it = all_subscribers_.begin(); it != all_subscribers_.end(); ++it) {+			if (*it == s) {+				all_subscribers_.erase(it);+				return;+			}+		}+		NEVER_HERE();+	}++	Signal() = default;+	~Signal() {+		owned_subscribers_.clear();+		// Any subscribers not owned by us should have been destroyed by their owner by now+		assert(all_subscribers_.empty());+	}++private:+	mutable std::set<std::unique_ptr<SignalSubscriber>> owned_subscribers_;

This is an age old debate - I remember having it at Google a few times. Should "const" mean - conceptually this is constant? or should it mean the bytes of this data structure do not change. We felt that using mutable let subtle bugs creep in, i.e. in our projects we opted for making classes non-const instead of using mutable. I do understand that this would introduce a much large change in the code base. I suggest to add a comment here that basically said what you explained me in writing.

Noordfrees

comment created time in 13 days

PullRequestReviewEvent

pull request commentSirVer/ultisnips

Added remote debug facilities (remote pdb server)

Thanks for this contribution and sorry for my slowness!

hl037

comment created time in 13 days

push eventSirVer/ultisnips

Léo Flaventin Hauchecorne

commit sha 2c83e40ce66814bf813457bb58ea96184ab9bb81

Added remote debug facilities (remote pdb server) (#1404) * Added remote debug facilities * Added options to the test suite to enable the remote debug server * Improved documentation on debugging * Debugging informations -> Advanced documentation * Back to py 3.5

view details

push time in 13 days

PR merged SirVer/ultisnips

Added remote debug facilities (remote pdb server)

As discussed in #1403, and since you seemed enthusiast about it, I polished the remote debugger / post-mortem in something quite usable even though some stuff are still missing (like handling correctly arrow and completion keys...)

I am a bit sorry the code is somewhat messy, it was not that easy to make sure issuing a quit command would close the socket with vim resuming as if no debugger were launched, but at least, I tested it with pdb and pdb++ with all configuration possibility and it does what it is asked for, without altering UltiSnips when not enabled (I ran the test suite, and I have no fails).

Please don't ask me to provide a test case, I have truly no idea of how I would implement it =D

+307 -6

10 comments

8 changed files

hl037

pr closed time in 13 days

PullRequestReviewEvent

pull request commentSirVer/ultisnips

Added remote debug facilities (remote pdb server)

Not too concerned about the freezing, we seem to have this on master already. Of course it would be better if the test suite actually was green, but that is definitely not your problem :)

Let's get the 3.5 compatibility reestablished and do a removal of 3.5 in another merge request if you feel strongly about it. I am willing to see if people still care.

hl037

comment created time in 14 days

pull request commentSirVer/ultisnips

Added remote debug facilities (remote pdb server)

If needed, I could use .format instead, but I really do think dropping python < 3.6 support would be the best...

This should be a separate discussion and a separate MR, let's not conflate this with this feature.

hl037

comment created time in 14 days

pull request commentwidelands/widelands

Replace `boost::signals2`

neat :). I did one pass over the code, a few questions around the implementation.

Noordfrees

comment created time in 14 days

more