Getting GTK auto complete/syntax highlighting to work on emacs on macOS

I recently wrote an article on getting gtk auto complete/syntax highlighting on macOS

its a genuinely fun hobby to make portable software, and this method will ultimately help in porting software to the macOS platform

a copy and paste:


before I continue, I want to mention that emacs auto completion, using company-mode, is rather slow when it comes to parsing a ton files, and in some configurations, especially recursively when it comes to parsing and displaying functions and macros, even when using the semantic auto complete system, but I do believe it speeds up when you initially parse and save to ctags or when you build a semanticdb, functions such as g_signal_connect() and macros such as G_APPLICATION however, did not work with company modes auto complete, but worked with flycheck on the fly syntax checking, using this method, and I haven’t had time to perfect an emacs configuration; maybe some time next week

you will need gtk installed from brew or ports, since gtk has trouble compiling from source on some Mac configurations. this method works with whatever version of gtk is reported by pkg-config –cflags (pkg-config --cflags gtk. you will also need pkg-config installed, multiple installations of gtk can be used and utilized

but the emacs plugins you’ll need are (and you’ll need to connect to Melpa using list-packages https://melpa.org/#/getting-started to have these automatically downloaded and configured):

company company-c-headers flycheck flycheck-pkg-config exec-path-from-shell (this allows x11emacs to read the shells configuration, may be option for terminal based emac uses) optional: function-args-mode, but when fa-show-auto is used, it breaks themes in emacs

download all of them through M-x list-packages (which means pressing alt+x, macOS option+x, which should issue an input on the bottom of emacs, where the status bar is), after that, type list-packages or use auto completion, aka ctrl+tab to cycle through possible candidates

open a c file (C-f ~/test.c) (which is control+x, macOS control+x) type in: M-x semantic-mode M-x semantic-customize-system-include-path in semantic-customize-system-include-path, add the path to the gtk version you intend to develop for, in my case /opt/homebrew/Cellar/gtk4/4.16.12/include/gtk-4.0 using the text based interface; you should be able to use your mouse (click ins after where it says /usr/include. semantic is included in emacs. options are automatically saved at command) M-x exec-path-from-shell-initialize M-x flycheck-mode M-x flycheck-pkg-config in flycheck-pkg-config, press enter, and then type the name of the version of gtk that provides valid input from pkg-config (ie gtk4) M-x global-company-mode

if you need to bind ctrl+tab to auto complete, you can add this to your config (~/.emacs.d/init.el)

(global-set-key (kbd “C-<tab>”) ‘company-semantic)

this will do most of the grunt work when plugins are installed (ctrl-tab shows a window to auto complete, ctrl+` (thats the key before 1, with shift it becomes ~) shows function argument. fa-show-auto automatically shows function prototypes, but can break emacs themes:

(require ‘package) (add-to-list ‘package-archives ‘(“melpa” . “https://melpa.org/packages/&#8221;) t) ;; Comment/uncomment this line to enable MELPA Stable if desired. See package-archive-priorities ;; and package-pinned-packages. Most users will not need or want to do this. ;;(add-to-list ‘package-archives ‘(“melpa-stable” . “https://stable.melpa.org/packages/&#8221;) t) (package-initialize)

(global-company-mode t) (global-flycheck-mode t) (semantic-mode t) (function-args-mode)

(global-company-mode t) (global-flycheck-mode t) (semantic-mode t) (function-args-mode) (global-set-key (kbd “C-<tab>”) ‘company-semantic) (global-set-key (kbd “C-`”) ‘fa-show)

if you need to compile from inside emacs, I would make a Makefile according to the gtk tutorial on gtk.org


I also have another article on getting Xcode to work with gtk, which is more reliable: https://unix-world.com/2025/01/25/getting-gtk4-to-work-in-xcode-with-auto-complete-and-syntax-highlighting/

website is unix-world.com and I welcome any and all traffic !

Getting GTK auto complete/syntax highlighting to work on emacs on macOS
 
 
Q