I need a keybinding (either a key like F12
or a mnemonic key sequence like SPC f12
) in Spacemacs. When hitting the keybinding in a window containing a file in its buffer the shell script script
in the directory the file is located in shall be executed.
Which one of the alternatives to define key bindings should I use? I thought about calling a function when the key binding is triggered. How could I get the directory the file in the current window buffer is located in when this function is executed? But probably there is another way to solve this problem.
(buffer-file-name)
have the variabledefault-directory
set to the directory of the file. In most cases that is what(file-name-directory (buffer-file-name))
returns. Do you mean that by "root directory of the file in buffer"? Note that for a Linux user the wording "root directory of file in buffer" looks somewhat strange. AFAIK, there the root directory always is/
.SPC o
andSPC m o
are guaranteed to never conflict with default bindings and which are reserved for users. Can be used instead of e.g.(global-set-key [f12] 'run-script)
.