2

I often use the Geany text editor to write programming code. I recently knew that we can insert a code snippet in Geany automatically using some keybindings and I liked the idea of that.

So, I went through some of the basics of the snippets in the Geany manual.

And I tried to do this: A required snippet for an Octave script is:

#!/usr/bin/octave -qf
% Author   : Bhishan Poudel
% Date     : 

I_like_this_to_be_inserted_automatically

My attempt so far:

We have to edit the configuration file called "snippets.conf" which can be accessed like this:

Menu ToolsConfiguration Filessnippets.conf

Or ~/.config/geany/snippets.conf.

Then, I first checked the file type for Octave scripts:

geany --ft-names 

I see the filetype is [Matlab/Octave]. So, I added the following code there.

[Matlab/Octave]
pre=#!/usr/bin/octave -qf \n% Author    : Bhishan Poudel \n% Date      : {date}\n\n

Note: to find the shebang path for octave installation directory, type which octave

Then to implement the code I created a file called a.m and opened it in Geany. Then the command to try this snippet is *preTab (type pre followed by Tab) then the output is:

#!/usr/bin/octave -qf
% Author    : Bhishan Poudel
% Date      : 2016-05-23

How can we change the date format to May 23, 2016?

Some useful links are following:
http://www.geany.org/manual/0.18.1/index.html#user-definable-snippets

1
  • I don't think this is really relevant to Octave nor MATLAB Commented May 23, 2016 at 19:28

1 Answer 1

1

One way to do it is to use {command: date} with date's default command line syntax. So in your case I think it would be

{command:date +"%b %d, %Y"}

Which results here into:

$ LANG=C date +"%b %d, %Y"
May 24, 2016

Another more general way would be to set up a template for your Octave scripts. Inside your template you should be able to insert values based on Geany's configuration. Have a look into the manual, but something like this saved as a template could work (untested):

#!/usr/bin/octave -qf
% Author    : {developer} <{mail}>
% Date      : {date}

But you would need to configure date-format in Geany's preferences — where you can use the options from above.

Sign up to request clarification or add additional context in comments.

6 Comments

What is the line break symbol in geany configuration? To make a template I have make very long line, is there way I can do line break?
Not sure where you want to add it, but try \n
Also what is %b symbol, is this same as %m?
Here, new line is \n. I am talking about line break symbol \ (such as in C or Python), ... (in matlab/octave).
Inside a template you can use normal line breaks. Snippets doesn't support line breaks.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.