I want to make a few customizations to cmake-model.el. The big-picture view of this lisp file is as follows:
...
;; This function I want to modify
(defun cmake-indent ()
...
)
...
;; Mode definition.
;;
;;;###autoload
(define-derived-mode cmake-mode cmake--parent-mode "CMake"
"Major mode for editing CMake source files."
...
)
What I want to do is to create a minor mode ros-mode
which would override the cmake-indent()
function with my own, but keep everything else the same compared to the original cmake-mode.el. The mode line should show ROS
when the minor mode is active.
I have no experience with creating minor modes, but I feel like this should be easy for someone with experience. Thank you for helping!
(set (make-local-variable 'indent-line-function) 'cmake-indent)
All you need to do is change it to something like(set (make-local-variable 'indent-line-function) 'my-cmake-indent)
where your new function is calledmy-cmake-indent
. You don't really need aminor-mode
, but you can Google that if you want -- you only need that one (1) line of code and change the mode-line lighter to" ROS"
and you are done. You can also Google things like: setq "indent-line-function" emacs to see other examples.cmake-mode
is available?major-mode
(which is not what you want) -- you may wish to instead Google for: "define-minor-mode" emacs And, of course, you want to restore the original value ofindent-line-function
when theminor-mode
is turned off.ros-mode
in the first place (with all the desired personal configurations) instead ofcmake-mode
? Or even if you have to invoke it manually, wouldn't a major mode still fit the bill? (i.e. would you ever want to toggle a minorros-mode
on and off again for any given file? It sounds like you would just want it on for such files?)(define-minor-mode ros-mode "A minor-mode for working with ROS (Robot Operating System)-specific files." :init-value nil :lighter " ROS" :keymap nil :global nil :group 'cmake (cond (ros-mode (setq-local indent-line-function 'my-cmake-indent) (when (called-interactively-p 'any) (message "Turned ON 'ros-mode'."))) (t (if (eq major-mode 'cmake-mode) (setq-local indent-line-function 'cmake-indent) (kill-local-variable 'indent-line-function)) (when (called-interactively-p 'any) (message "Turned OFF 'ros-mode'.")))))