To highlight the dollar sign on double-click in Geany 1.36 for PHP, you must modify the Scintilla lexer properties within your language definition file. Specifically, add the character to the wordchars property for the PHP lexer. This ensures that the editor treats the dollar sign as part of a word during selection, rather than ignoring it or splitting the variable name.
Understanding Geany’s Lexing Engine
Geany relies on the Scintilla editing component for syntax highlighting and text processing. Scintilla uses "lexers" to parse code into tokens. When you double-click a word, Scintilla selects a range of characters defined as "word characters." By default, the PHP lexer does not include the dollar sign ($) in its set of word characters because, syntactically, the dollar sign is a prefix operator for variables, not part of the identifier itself.
However, many developers prefer to select the entire variable reference, including the leading dollar sign, with a single click. To achieve this, we need to tell the PHP lexer to treat $ as a valid character within a word. This is done through lexer properties, specifically the wordchars property. It is crucial to understand that this configuration is not stored in a simple XML file or a global settings dialog in older versions like 1.36. Instead, it resides in the language definition files that Geany loads at startup.
Locating the Language Definition File
The first step is to find the correct language definition file for PHP. In Geany 1.36, these files are typically located in the installation directory under a subfolder nameddata, then geany, then langs. The specific file you need is usually named php.lang.
If you installed Geany from a package manager (like apt on Ubuntu or Homebrew on macOS), the path might be something like /usr/share/geany/langs/php.lang. On Windows, it is often found in C:\Program Files\Geany\share\geany\langs\php.lang. You will need administrative privileges to edit this file if it is in a system directory. Alternatively, you can copy the file to your user-specific configuration directory to avoid permission issues and ensure your changes persist across updates. The user-specific path is usually ~/.config/geany/langs/ on Linux/macOS or %APPDATA%\Geany\langs\ on Windows.
Creating a User-Specific Override
It is highly recommended to create a user-specific override rather than modifying the system-wide file. This prevents your changes from being overwritten when you update Geany. 1. Navigate to your user configuration directory for Geany. 2. Create a folder namedlangs if it does not already exist.
3. Copy the original php.lang file from the system directory into this new langs folder.
4. Open the copied php.lang file in a text editor.
By placing the file in your user directory, Geany will prioritize this version over the system default, allowing you to customize the behavior safely.
Modifying the Lexer Properties
Open thephp.lang file in your preferred text editor. Look for the section labeled [lexer_properties]. This section contains key-value pairs that configure the Scintilla lexer for PHP. If the section does not exist, you may need to add it.
You need to modify the wordchars property. This property defines which additional characters are considered part of a word for the purpose of selection and auto-completion. The default value usually includes alphanumeric characters and underscores. To include the dollar sign, you must append it to this list.
Find the line that looks like this:
wordchars=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_
Change it to include the dollar sign:
wordchars=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_$
Note that the dollar sign must be escaped or handled carefully depending on the parser, but in standard Geany language files, adding it directly to the string is sufficient. Ensure there are no spaces around the equals sign unless required by the specific format, though Geany generally ignores whitespace here.
After making this change, save the file.
Applying the Changes
Once you have saved the modifiedphp.lang file, you need to restart Geany for the changes to take effect. Geany loads language definitions at startup, so simply opening a file will not reload the lexer properties.
1. Close all open files in Geany.
2. Exit the application completely.
3. Reopen Geany.
4. Open a PHP file.
5. Double-click on a variable name, such as $myVariable.
You should now see the entire string, including the leading dollar sign, selected. This makes copying and pasting variable references much faster and reduces the need for multiple clicks or manual adjustments.
Troubleshooting
If the change does not work, verify that you are editing the correct file. Geany might be loading the system-wide file instead of your user-specific one. You can check which file is currently loaded by looking at the status bar or by checking the Geany logs if available. Also, ensure that you did not introduce any syntax errors in thephp.lang file, such as missing brackets or incorrect formatting, which could cause Geany to fall back to defaults or fail to load the language definition.
For more advanced customization of syntax highlighting, you might also want to explore how other editors handle similar issues, as seen in our guide on Extending C# Syntax Highlighting in the Latest gVim: A Tech Support Guide. While the mechanisms differ, the principle of defining lexer rules remains consistent across many code editors.
Frequently Asked Questions
Why doesn't double-clicking select the dollar sign by default?
By default, programming languages treat the dollar sign as a special prefix character for variables, not as part of the identifier itself. Most lexers define "word characters" as letters, numbers, and underscores, excluding symbols to prevent accidental selection of surrounding punctuation.Will updating Geany overwrite my custom php.lang file?
No, if you placed your modifiedphp.lang file in your user-specific configuration directory (such as ~/.config/geany/langs/), it will remain untouched during updates. System-wide files are overwritten, but user overrides are preserved separately.
Can I apply this change to other languages like Python or JavaScript?
Yes, you can follow the same process for other languages. Locate the corresponding language file (e.g.,python.lang or javascript.lang) in the langs directory and modify the wordchars property to include any relevant symbols for those languages.
What if I don't see a [lexer_properties] section in the file?
If the section is missing, you can add it manually at the end of the file before the closing bracket. Ensure the format matches the existing properties, using key-value pairs separated by an equals sign.How do I revert this change if I don't like it?
Simply delete the modifiedphp.lang file from your user-specific directory. Geany will then automatically fall back to the default system-wide language definition, restoring the original double-click behavior.