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 Tools → Configuration Files → snippets.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
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.