How to write macro for Notepad++?

Macros in Notepad++ are just a bunch of encoded operations: you start recording, operate on the buffer, perhaps activating menus, stop recording then play the macro. After investigation, I found out they are saved in the file shortcuts.xml in the Macros section. For example, I have there: <Macro name=”Trim Trailing and save” Ctrl=”no” Alt=”yes” Shift=”yes” … Read more

Generating documentation in macros

It is possible to capture doc comments in macro invocations. It is not widely-known, but Rust documentation is actually represented as a special kind of attribute on an item. For example: /// Some documentation comment pub fn function() {} // is equivalent to #[doc=”Some documentation comment”] pub fn function() {} And it is possible to … Read more

Equivalent of __func__ or __FUNCTION__ in Rust?

You can hack one together with std::any::type_name. macro_rules! function { () => {{ fn f() {} fn type_name_of<T>(_: T) -> &’static str { std::any::type_name::<T>() } let name = type_name_of(f); name.strip_suffix(“::f”).unwrap() }} } Note that this gives a full pathname, so my::path::my_func instead of just my_func. A demo is available.

How far can LISP macros go? [closed]

That’s a really good question. I think it’s nuanced but definitely answerable: Macros are not stuck in s-expressions. See the LOOP macro for a very complex language written using keywords (symbols). So, while you may start and end the loop with parentheses, inside it has its own syntax. Example: (loop for x from 0 below … Read more

Collection of Great Applications and Programs using Macros

Culpepper & Felleisen, Fortifying Macros, ICFP 2010 Culpepper, Tobin-Hochstadt and Felleisen, Advanced Macrology and the Implementation of Typed Scheme, Scheme Workshop 2007 Flatt, Findler, Felleisen, Scheme with Classes, Mixins, and Traits, APLAS 2006 Herman, Meunier, Improving the Static Analysis of Embedded Languages via Partial Evaluation, ICFP 2004

How to allow optional trailing commas in macros?

Handle both cases You can handle both cases by… handling both cases: macro_rules! define_enum { ($Name:ident { $($Variant:ident,)* }) => { pub enum $Name { None, $($Variant),*, } }; ($Name:ident { $($Variant:ident),* }) => { define_enum!($Name { $($Variant,)* }); }; } define_enum!(Foo1 { A, B }); define_enum!(Foo2 { A, B, }); fn main() {} We’ve … Read more

Macros in Swift?

In this case you should add a default value for the “macro” parameters. Swift 2.2 and higher func log(message: String, function: String = #function, file: String = #file, line: Int = #line) { print(“Message \”\(message)\” (File: \(file), Function: \(function), Line: \(line))”) } log(“Some message”) Swift 2.1 and lower func log(message: String, function: String = __FUNCTION__, … Read more