Geany4Windows text editing - geany

I have used Geany4Windows for a long while but am still confused how it handles editing text files and I decided to ask for help now!
If I open a new file from menu I can type plain text in it and yet when I save the file it does not give a .txt extension option to save as and while I can add this to the end of the name I give to the file and save it and it saves as a .txt file with no problem. If instead, I do not do this and leave off the file extension, and then save it, it saves as a file with no extension!
There is an option to open a new template file but in my Geany4Windows there is no .txt template. I tried making my own by making a file with a {fileheader} and saving it in C:\Program Files (x86)\Geany\data\templates\files as file.txt.
This does then give me the option to open a new template text file but when I save that the text fileheader produces this:
/*
* mynewdefaulttexttemplateGeany.txt.txt
*
* Copyright 2014 Richard <Richard#RPDHPI5PAVILION>
*
* 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.
*
*
*/My first text file from new text template I just created in Geany.....
The file header shows as >> mynewdefaulttexttemplateGeany.txt.txt << with a double .txt extension.
If I could fix this file header for my default template file.txt file (so it doesn't save with the extension added twice), I would be happier working with plain text files in Geany4Windows! Anyone know how I can fix this please? Thanks.
MY EDIT
I have fixed this now and it was helped by Matthews post below (& see my comment on that).
To recap the solution:
I made a new custom file type file.txt with {fileheader}
To make this work I added the line txt=*.txt to filetype_extensions.conf
Also I created filetypes.txt.conf and added..
[settings]
extension=txt
lexer_filetype=C
[styling=C]
# multiline comments
comment_open=/*
comment_close=*/
This works now! See screenshots before & after:
after:
I do like Geany4Windows but it can be interesting trying to customise it to use new filetypes etc etc. Happy coding & editing with Geany on Windows & Linux (does it run on Mac?!). I'm pleased this is fixed now. :-)

You could create a file named like filetypes.Text.conf and inside of it put:
[settings]
extension=txt
Then add it to filetype_extensions.conf [Extensions] section like:
...
Text=*.txt;*.text; etc...
...
The manual has more details about custom filetypes.

You can create a *.txt-file by saving your file like foo.txt or baa.txt. Plain text not necessarily having txt-extension.

To explain Matthews answer more, you have been using filetype None, which does not have an extension. By creating the filetype Geany now knows about files with extension .txt
BTW you can edit filetype_extensions.conf by menu->tools->configuration files-> filetype_extensions.conf.

Related

How to prevent specific line/s inside a notepad file from being edited?

I have a file that can be opened thru notepad application.
Basically, this file(which can be opened thru notepad) is created by a software and that software uses the values inside that file to run. You can edit the values inside the file using its software.
I just want specific lines(values) to be restricted from being edited because I am implementing strict values inside that file that no one will be able to edit except me.
Is there any clever way to restrict specific lines inside that file from being edited?
I tried the basic way - I used the change permission read/write on that file but I can't change ANY values inside the file which is undesirable.
Note: I have very little to no experience about python, c++, or java but any suggestion will give me idea to learn from it.
Edit:
Here's an example inside the file:
[Type Data]
Comment=Standard Dispense
[Shared_A]
802=1
807=750
11=0
12=0
.
What I want is restrict the value from row/column "807" which is equal to number 750.
I want this number 750 not to be edited even from the software so that other people will not mess it up. I want to set this value as standard value.
Is there any program that you can write inside that file so that it cannot be edited from the software unless I open that file and edit it?
I work from a production/manufacturing company that uses the software that is used for dispensing.
A text file is simply a sequence of bytes that represent code units to encode code points in any given character set. Every byte value is a potentially legal character encoding, leaving no values to encode additional semantics (like guard regions).
With that it should be obvious that there is nothing you can do to partially limit editing of a file using a standard text editor. Whatever problem you are trying to solve, this is not a solution. Next time around you might want to ask about the problem you are trying to solve rather than your proposed solution.

Rules for file extensions?

Are there any rules for file extensions? For example, I wrote some code which reads and writes a byte pattern that is only understood by that specific programm. I'm assuming my anti virus programm won't be too happy if I give it the name "pleasetrustme.exe"... Is it gerally allowed to use those extensions? And what about the lesser known ones, like ".arw"?
You can use any file extension you want (or none at all). Using standard extensions that reflect the actual type of the file just makes things more convenient. On Windows, file extensions control stuff like how the files are displayed in Windows Explorer and what happens when you double click on it.
I wrote some code which reads and writes a byte pattern that is only
understood by that specific programm.
A file extension is only an indication of what type of data will be inside, never a guarantee that certain data formatted in a specific way will be inside the file.
For your own specific data structure it is of course always best to choose an extension that is not already in use for other file formats (or use a general extension like .dat or .bin maybe). This also has the advantage of being able to use an own icon without it being overwritten by other software using the same extension - or the other way around.
But maybe even more important when creating a custom (binary?) file format, is to provide a magic number as the first bytes of that file, maybe followed by a file header structure containing a version number etc. That way your own software can first check the header data to make sure it's the right type and version (for example: anyone could rename any file type to your extension, so your program needs to have a way to do some checks inside the file before reading the remaining data).

Custom syntax highlighting in Geany

I am trying to create custom syntax highlighting for Kivy '.kv' files in the Geany editor. Although the specific filetype seems irrelavant to the issue I'm having, as any efforts I make at getting syntax highlighting to work for a custom filetype results in a completely non-highlighted file. I believe I have done my homework on this, and nothing seems to work.
I have added the following to ~/.config/geany/filetype_extensions.conf
Kivy=*.kv;
I also have a custom type definition file named 'filetypes.Kivy.conf' in ~/.config/geany/filedefs/. I have tried basing this file off several of the stock type definition files in /usr/share/geany/ and the file never gets any syntax highlighting applied in Geany. Right now, just for experimentation's sake, my 'filetypes.Kivy.conf' file looks like this:
# For complete documentation of this file, please see Geany's main documentation
[settings]
# default extension used when saving files
extension=kv
# single comments, like # in this file
comment_single=#
[keywords]
# all items must be in one line
primary=size canvas
secondary=pos size
[indentation]
width=4
# 0 is spaces, 1 is tabs, 2 is tab & spaces
type=0
This is very loosly based on the stock XML definition file, but like I said I've tried many other stock files. In many cases I only changed the 'extension=' value to kv and still no highlighting was applied, even though going to Document>Set Filetype in Geany and choosing virtually any random filetype (besides my custom entry) would yeild some sort of highlighting within my .kv file. This is even the case when using the unmodified contents of a stock definition which otherwise works fine on my .kv file when specifically selected in Geany!
Also, the Kivy filetype is listed and selected by default in Document>Set Filetype within Geany, so I must be doing something right here!
I realize this similar question has been asked, but the solutions seem irrelavent to my case, as I've tried every related topic on this and many other sites. My Geany version is 1.22 and I'm running Arch Linux. This is driving me nuts - any suggestions?
Thank you!
Set lexer_filetype= property in the [settings] section of your filetype file. Working highlighting requires that there is a lexer that could be used for highlighting the .kv-files.
For more info see http://www.geany.org/manual/#lexer-filetype
There are three important things to obey:
the configuration file should be placed in "~/.config/geany/filedefs"
the configuration file must have the extension ".conf" - otherwise it won't show up at all (the files in "/usr/share/geany/filesdefs", where I copied my base file from, do not have a ".conf" extension!)
you must set the "lexer_filetype" to an existing (presumably builtin) configuration; e.g. "lexer_filetype=Python"

Purpose of "$Id: ..." line in the header of source files

/* $Id: file.c,v 1.0 2010/09/15 01:12:10 username Exp $ */
I find this line in many source code files in the comment at the top (header) of the file. Why? Is it aimed for the version control software? -Thanks.
These sort of comments are automatically modified by various source code control systems, things like author, date, history and so forth.
See here for some common ones for RCS which is the first source code control system I ever saw to implement this sort of thing (that doesn't mean it was the first, just that RCS was the first I ever used and it had that capability).
One particular trick we used to use was to put the line:
static char *fileId = "$Id: $";
into the source file (and header files as well, although the names had to be unique) so that, when it was built, it would automatically have the ID of the files in the executable itself.
Then we could use something like strings to find out which source files were used to build the executable. Ideal for debugging problems in the field.
It tells CVS (and other VCSs) to expand the value of the Id at check-out time, so anybody reading the source file in question will know what version exactly was checked out for it. Not very popular any more (you can always ask your VCS for such info if you keep the source file in a client / repository / working directory -- or however else your VCS calls such things;-).
I believe you are correct. It appears to be a keyword substitution string for CVS.
Take a look at this question $id: name of file, date/time creation Exp $

What information to put in comments at the top of a sourcecode file?

What information do you consider worth to put in the comment at the beginning of a sourcecode file?
All I could think about was the name of the author and perhaps the date the file was created (although I'm not to sure if there is any useful value to this information).
[EDIT] To clarify, I don't mean comments before a class, but at the first lines of the file, before include statements and what else. Like
/**
* Author: Name
* Created: 11.05.2009
*
* (c) Copyright by Blub Corp.
**/
What to put in the file header:
Library/component that source code is part of
Copyright details
Brief and meaningful description of class(es) in source file
What NOT to put in the file header:
Anything that duplicates low level logic which is part of the code itself. This can lead to maintenance problems if it isn't updated when the source code changes.
Author name(s). Why?
In the world of revision control systems, while there may be an initial author of some code, eventually ownership becomes blurred. This is especially true when code enters the maintenance phase of the life cycle where owners can change regularly.
All code eventually becomes "community wiki" after enough changes ;-)
Would you want your name associated with all of the code forever, knowing full well that you will not be responsible for the code until its death?
Creation and last changed dates. This is for similar reasons as list above. Revision control includes this information - why duplicate it in the header, making more work for yourself and risking leaving inaccurate information in the comment when things inevitably change?
Copyright
Original author(s)
License (if it's open-source)
One-line purpose statement or description
Further overall documentation and usage examples
Edit: Changed Author(s) to Original Author(s)
if the file is going to contain some very common class / functionality which can be understood with reasonable common sense, then you dont really need to put much in the description otherwise if the source code file is a class / function very specific to the project or is encompassing a complicated logic, then you should give a high level overview & purpose of the source code file.
File Encoding! (utf-8)
# -*- encoding: utf-8 -*-
Especially if you plan on sharing your code with someone else in some other part of the world at some point.
with all the above also put sort detail of the purpose of the code in that file also something u think can be helpful in debugging and understanding the functionality.this help in maintainence and support.

Resources