@Dmitry made a great point that hippie-expand
will do what I'm desiring when :
is considered a punctuation character.
It's obviously not ideal to just set (modify-syntax-entry ?: "." ruby-mode-syntax-table)
in your init and call it a day, because then only some_action
in :some_action
is considered a symbol which would break expectations for other plugins. This seems ripe for re-defining with advice though.
Here's what I came up with:
(defun hippie-expand-ruby-symbols (orig-fun &rest args)
(if (eq major-mode 'ruby-mode)
(let ((table (make-syntax-table ruby-mode-syntax-table)))
(modify-syntax-entry ?: "." table)
(with-syntax-table table (apply orig-fun args)))
(apply orig-fun args)))
(advice-add 'hippie-expand :around #'hippie-expand-ruby-symbols)
If hippie-expand
is called when the major-mode is ruby-mode
, define a cloned temporary syntax table where :
is a punctuation character and call hippie-expand
with it. Otherwise, just call hippie-expand
as normal.
Any downside to this approach?