Add missing header include.
[geany-mirror.git] / HACKING
blobfe185cc39edd5b732f0c22058a3f3f1813409fda
1 =============
2 Hacking Geany
3 =============
4 .. contents::
6 General
7 =======
9 About this file
10 ---------------
11 This file contains information for anyone wanting to work on the Geany
12 codebase. You should be aware of the open source licenses used - see
13 the README file or the documentation. It is reStructuredText; the
14 source file is HACKING. You can generate hacking.html by running ``make
15 hacking-doc`` from the doc/ subdirectory.
17 Writing plugins
18 ---------------
19 * src/plugindata.h contains the plugin API data types.
20 * See plugins/demoplugin.c for a very basic example plugin.
21 * src/plugins.c loads and unloads plugins (you shouldn't need to read
22   this really).
23 * The API documentation contains a few basic guidelines and hints to
24   write plugins.
26 You should generate and read the plugin API documentation, see below.
28 Plugin API documentation
29 ^^^^^^^^^^^^^^^^^^^^^^^^
30 You can generate documentation for the plugin API using the doxygen
31 tool. Run ``make api-doc`` in the doc subdirectory. The documentation
32 will be output to doc/reference/index.html.
33 Alternatively you can view the API documentation online at
34 http://www.geany.org/manual/reference/.
36 Patches
37 -------
38 We are happy to receive patches, but it's best to check with us by email
39 or mailing list whether a new feature is appropriate, and whether someone
40 is already working on similar code.
42 In general it's best to work from the current SVN, but we accept patches
43 against other releases::
45         $ svn diff > fix-some-bug.patch
47 If you're not using SVN, you can use the diff command::
49         $ diff -u originalpath modifiedpath > new-feature.patch
51 Please make sure patches follow the style of existing code - In
52 particular, use tabs for indentation. See `Style`_ and `Coding`_.
54 For Windows:
55 Subversion (SVN): http://subversion.tigris.org/
56 diff, grep, etc: http://mingw.org/ or http://unxutils.sourceforge.net/.
57 See also the 'Building on Windows' document on the website.
59 File organization
60 -----------------
61 callbacks.c is just for Glade callbacks.
62 Avoid adding code to geany.h if it will fit better elsewhere.
63 See the top of each ``src/*.c`` file for a brief description of what
64 it's for.
66 Keeping the plugin ABI stable
67 -----------------------------
68 Please be aware that anything with a doc-comment (a comment with an
69 extra asterix: ``/**``) is something in the plugin API. Things like
70 enums and structs can usually still be appended to, ensuring that all
71 the existing elements stay in place - this will keep the ABI stable.
73 .. warning::
75         Some structs like GeanyKeyGroup and GeanyCallback cannot be
76         appended to without breaking the ABI because they are used to declare
77         structs by plugins, not just for accessing struct members through
78         a pointer.
80 Before the 1.0 release series, the ABI can change when necessary, and
81 even the API can change. An ABI change just means that all plugins will
82 not load and they must be rebuilt. An API change means that some plugins
83 might not build correctly.
85 When reordering or changing existing elements of structs that are
86 used as part of the plugin API, you should increment GEANY_ABI_VERSION
87 in plugindata.h. This is usually not needed if you're just appending
88 fields to structs. The GEANY_API_VERSION value should be incremented
89 for any changes to the plugin API, including appending elements.
91 If you're in any doubt when making changes to plugin API code, just ask us.
93 Glade
94 -----
95 Use the code generation features of Glade instead of editing interface.c
96 or support.c. Glade 2.12 is recommended as long as we support GTK+ 2.8,
97 because later versions of Glade are not 100% compatible with GTK+ 2.8
98 (e.g. they may use functions added in GTK+ 2.10).
100 You can build Glade 2.12 and run the binary in place, without installing
101 it - this should work fine even if you have another version of Glade
102 installed on the system.
104 GTK API documentation
105 ---------------------
106 The official GTK 2.8 API documentation is not available online anymore,
107 so we put them on http://www.geany.org/manual/gtk/.
108 There is also a tarball with all available files for download and use
109 with devhelp.
111 Using the 2.8 API documentation of the GTK libs (including GLib, GDK and
112 Pango) has the advantages that you don't get confused by any newer API
113 additions and you don't have to take care about whether you can use
114 them or not.
115 This is because Geany depends on GTK 2.8. API symbols from newer
116 GTK/GLib versions should be avoided to keep the source code building
117 against GTK 2.8.
119 Coding
120 ------
121 * Don't write long functions with a lot of variables and/or scopes - break
122   them down into smaller static functions where possible. This makes code
123   much easier to read and maintain.
124 * Use GLib types and functions - e.g. g_free instead of free.
125 * Your code should build against GLib 2.8 and GTK 2.8. At least for the
126   moment, we want to keep the minimum requirement for GTK at 2.8 (of
127   course, you can use the GTK_CHECK_VERSION macro to protect code using
128   later versions).
129 * We currently try to support the old GCC 2.9.x compiler,
130   so we always declare variables before statements. You can use
131   -Wdeclaration-after-statement in your ./configure CFLAGS to warn about
132   this.
133 * You should also try to write ISO C90 code for portability, so always
134   use C ``/* */`` comments and function_name(void) instead of
135   function_name().  This is for compatibility with various Unix-like
136   compilers. You can use -ansi in your CFLAGS to help check this.
138 Style
139 -----
140 * We use a tab width of 4 and indent completely with tabs not spaces.
141 * Use the multiline comment ``/* */`` to comment small blocks of code,
142   functions descriptions or longer explanations of code, etc. C++ single
143   line comments will cause portability issues. The more comments are in
144   your code the better.
145 * Lines should not be longer than about 100 characters and after 100
146   characters the lines should be wrapped and more indented than the first
147   line to highlight that the line is continued.
148 * We don't put spaces between function names and the opening brace for
149   argument lists.
150 * Try to fit in with the existing code brace indenting style, comments,
151   operator spacing etc. It's not required for patches but it will save
152   us having to manually reformat them.
154 Libraries
155 ---------
156 We prefer to use an unmodified version of Scintilla - any changes should
157 be passed on to the maintainers at http://scintilla.org.
159 Tagmanager was originally taken from Anjuta 1.2.2, and parts of it
160 (notably c.c) have been merged from later versions of Anjuta and
161 CTags. The independent Tagmanager library itself ceased development
162 before Geany was started. It's source code parsing is mostly taken from
163 Exuberant CTags (see http://ctags.sf.net).
166 Notes
167 =====
168 Some of these notes below are brief (or maybe incomplete) - please
169 contact the geany-devel mailing list for more information.
171 Using pre-defined autotools values
172 ----------------------------------
173 When you are use macros supplied by the autotools like GEANY_PREFIX,
174 GEANY_LIBDIR, GEANY_DATADIR and GEANY_LOCALEDIR be aware that these
175 might not be static strings when Geany is configured with
176 --enable-binreloc. Then these macros will be replaced by function calls
177 (in src/prefix.h). So, don't use anything like
178 printf("Prefix: " GEANY_PREFIX); but instead use
179 printf("Prefix: %s", GEANY_PREFIX);
181 Adding a source file foo.[hc] in src/ or plugins/
182 -------------------------------------------------
183 * Add foo.c, foo.h to SRCS in path/Makefile.am.
184 * Add foo.o to OBJS in path/makefile.win32.
185 * Add path/foo.c to po/POTFILES.in (for string translation).
187 Adding a filetype
188 -----------------
189 You can add a filetype without syntax highlighting or tag parsing, but
190 check to see if those features have been written in other projects first.
192 * Add GEANY_FILETYPES_FOO to filetypes.h.
193 * Initialize GEANY_FILETYPES_FOO in init_builtin_filetypes() of
194   filetypes.c.
195 * Rebuild Geany.
196 * From your geany/ directory, run::
198         src/geany --generate-data-files
200 (The src/ prefix may be different, depending on where the binary is
201 generated.)
202 This will update data/filetype_extensions.conf. Note that
203 you need GEANY_DEBUG to be defined when building Geany for the
204 --generate-data-files argument to work - this is always defined in the
205 SVN version. Alternatively, edit the file by hand.
207 filetypes.* configuration file
208 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
209 All languages need a data/filetypes.foo configuration file. See
210 the "Filetype definition files" section in the manual and/or
211 data/filetypes.c for an example.
213 Programming languages should have:
215 * [keywords] if the lexer supports it.
216 * [settings] mostly for comment settings.
217 * [build_settings] for commands to run.
219 For languages with a Scintilla lexer, there should be a [styling] section,
220 to correspond to the styles used in styleset_foo() in highlighting.c -
221 see below.
223 Syntax highlighting
224 ^^^^^^^^^^^^^^^^^^^
225 It may be possible to use an existing Scintilla lexer in the scintilla/
226 subdirectory - if not, you will need to find (or write) one,
227 LexFoo.cxx. Try the Scintilla project first. When adding a lexer, update:
229 * scintilla/Makefile.am
230 * scintilla/makefile.win32
231 * scintilla/KeyWords.cxx - add a LINK_LEXER command *manually*
233 For syntax highlighting, you will need to edit highlighting.c and add
234 the following things:
236 1. Write styleset_foo_init() to setup default styles and load style
237    settings from the filetypes.foo configuration file. You should probably
238    start by copying and adapting another filetype's initialization, such
239    as styleset_tcl_init(). Another way is to use load_style_entries()
240    to make style initialization simpler - see styleset_c_like_init().
242 .. note::
243     Please try to make your styles fit in with the other filetypes' default
244     colors, and to use named styles where possible. Filetypes that share a
245     lexer should have the same colors. Normally, styles should leave the
246     background color empty to match the default color.
248 2. Write styleset_foo() to apply styles when a new scintilla widget
249    is created. Again you could copy and adapt a function like
250    styleset_tcl().
251 3. In highlighting_init_styles(), add
252    ``init_styleset_case(GEANY_FILETYPES_FOO, foo);``.
253 4. In highlighting_set_styles(), add
254    ``styleset_case(GEANY_FILETYPES_FOO, foo);``.
256 Error message parsing
257 ^^^^^^^^^^^^^^^^^^^^^
258 New-style error message parsing is done with an extended GNU-style regex
259 stored in the filetypes.foo file - see the [build_settings] information
260 in the manual for details.
262 Old-style error message parsing is done in
263 msgwin_parse_compiler_error_line() of msgwindow.c - see the ParseData
264 typedef for more information.
266 Other features
267 ^^^^^^^^^^^^^^
268 For brace indentation, update lexer_has_braces() in editor.c;
269 indentation after ':' is done from on_new_line_added().
271 If the lexer has comment styles, you should add them in is_comment_style()
272 in editor.c. You should also update is_string_style() for string/character
273 styles. For now, this prevents calltips and autocompletion when typing
274 in a comment (but it can still be forced by the user).
276 If the Scintilla lexer supports user type keyword highlighting (e.g.
277 SCLEX_CPP), update editor_lexer_get_type_keyword_idx() in editor.c.
279 Adding a TagManager parser
280 ^^^^^^^^^^^^^^^^^^^^^^^^^^
281 This assumes the filetype for Geany already exists.
283 First write or find a CTags compatible parser, foo.c. Note that there
284 are some language patches for CTags at:
285 http://sf.net/projects/ctags - see the tracker.
287 (You can also try the Anjuta project's tagmanager codebase.)
289 * Add foo.c to SRCS in Makefile.am.
290 * Add foo.o to OBJS in makefile.win32.
291 * Add Foo to parsers.h & fill in comment with parser number for foo.
293 In foo.c:
294 Edit FooKinds 3rd column to match a s_tag_type_names string in tm_tag.c.
296 In filetypes.c, init_builtin_filetypes():
297 Set filetypes[GEANY_FILETYPES_FOO].lang = foo's parser number.
299 In symbols.c:
300 Update init_tag_list() for foo, listing the tm_tag_* types corresponding
301 to the s_tag_type_names strings used in foo.c for FooKinds.
307 Stop on warnings
308 ^^^^^^^^^^^^^^^^
309 When a GLib or GTK warning is printed, often you want to get a
310 backtrace to find out what code caused them. You can do that with the
311 ``--g-fatal-warnings`` argument, which will abort Geany on the first
312 warning it receives.
314 But for ordinary testing, you don't always want your editor to abort
315 just because of a warning - use::
317     (gdb) b handler_log if level <= G_LOG_LEVEL_WARNING
320 Running with batch commands
321 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
322 Use::
324     $ gdb src/geany -x gdb-commands
326 Where ``gdb-commands`` is a file with the following lines::
328     set pagination off
329     b handler_log if level <= G_LOG_LEVEL_WARNING
330     r -d
333 Loading a plugin
334 ^^^^^^^^^^^^^^^^
335 This is useful so you can load plugins without installing them first.
336 Alternatively you can use a symlink in ~/.config/geany/plugins or
337 $prefix/lib/geany (where $prefix is /usr/local by default).
339 The gdb session below was run from the toplevel Geany source directory.
340 Start normally with e.g. "gdb src/geany".
341 Type 'r' to run.
342 Press Ctrl-C from the gdb window to interrupt program execution.
344 Example::
346         Program received signal SIGINT, Interrupt.
347         0x00d16402 in __kernel_vsyscall ()
348         (gdb) call plugin_new("./plugins/.libs/demoplugin.so")
349         ** INFO: Loaded:   ./plugins/.libs/demoplugin.so (Demo)
350         $1 = (Plugin *) 0x905a890
351         (gdb) c
352         Continuing.
354         Program received signal SIGINT, Interrupt.
355         0x00d16402 in __kernel_vsyscall ()
356         (gdb) call plugin_free(0x905a890)
357         ** INFO: Unloaded: ./plugins/.libs/demoplugin.so
358         (gdb) c
359         Continuing.