(cl-defun filename-from-buffer (&key get-ext get-path) (let ((filename (buffer-name)) (pathname (buffer-file-name))) (setq ret (car (split-string filename "\\."))) (when get-path (setq ret (car (split-string pathname "\\.")))) (when get-ext (setq ret filename)) (when (and get-ext get-path) (setq ret pathname)) ret))
I am fairly new to Emacs and Lisp (eLisp) and I wanted a function that would return the name of the file which is open in the current buffer. The function should take some optional arguments determining whether we want the full path, the extension or just the sole name of the file.
I feel like my implementation is pretty naive and it depends on the order of lines as well because I could not figure out how to do an
if-else chain and return within. So is there a more elegant/more secure or just a better way to do this? By better, I mean something that uses the functionality of language which is already provided, an implementation that does not depend on the order of cases and/or something that does branching in a better way.