1

I have emmet-mode installed and smart-tab installed and I want to rebind the default C-j of emmet to smart-tabs TAB.

(require 'emmet-mode)
(add-hook 'sgml-mode-hook 'emmet-mode) ;; Auto-start on any markup modes
(add-hook 'css-mode-hook  'emmet-mode) ;; enable Emmet's css abbreviation.
(setq emmet-move-cursor-between-quotes t) ;; default nil

(require 'smart-tab)
(global-smart-tab-mode 1)
(define-key emmet-expand-line [(tab)] 'smart-tab)

;;; http://www.emacswiki.org/emacs/TabCompletion
(defun hippie-unexpand ()
  (interactive)
  (hippie-expand 0))

(define-key read-expression-map [(shift tab)] 'hippie-unexpand)

This is the error

Warning (initialization): An error occurred while loading `c:/Users/Sayth/AppData/Roaming/.emacs.d/init.el':

Symbol's value as variable is void: emmet-expand-line

I am copying the format from here https://www.gnu.org/software/emacs/manual/html_mono/elisp.html#Remapping-Commands but I appear to be getting it wrong.

(define-key my-mode-map [remap kill-line] 'my-kill-line)

and this action is what is advised by the package author https://github.com/smihica/emmet-mode

press C-j to expand it (or alternatively, alias your preferred keystroke to M-x emmet-expand-line)

  • 1
    Are you trying to bind emmet-expand-line to TAB, or trying to make it one of the actions which smart-tab executes some of the time? In the latter case, it matters which particular implementation of smart-tab you're using. – npostavs Apr 8 '15 at 17:32
  • It is the later.github.com/genehack/smart-tab – sayth Apr 11 '15 at 21:41
2

https://github.com/genehack/smart-tab provides smart-tab-completion-functions-alist for adding per mode actions. It doesn't check parent modes, so to make it work for sgml-mode and all derivatives we can add an entry in the mode hook:

(require 'smart-tab)
(global-smart-tab-mode 1)

(defun add-emmet-expand-to-smart-tab-completions ()
  ;; Add an entry for current major mode in
  ;; `smart-tab-completion-functions-alist' to use
  ;; `emmet-expand-line'.
  (add-to-list 'smart-tab-completion-functions-alist
               (cons major-mode #'emmet-expand-line)))   

(require 'emmet-mode)
(add-hook 'sgml-mode-hook 'emmet-mode) ;; Auto-start on any markup modes
(add-hook 'sgml-mode-hook 'add-emmet-expand-to-smart-tab-completions)
(add-hook 'css-mode-hook  'emmet-mode) ;; enable Emmet's css abbreviation.
(add-hook 'css-mode-hook 'add-emmet-expand-to-smart-tab-completions)
...

and this action is what is advised by the package author https://github.com/smihica/emmet-mode

press C-j to expand it (or alternatively, alias your preferred keystroke to M-x emmet-expand-line)

They meant something like (define-key emmet-mode-keymap [tab] 'emmet-expand-line), but that would take over the tab key and you wouldn't be using smart-tab anymore.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.