Sometimes I have the date as part of the file name. And then when Emacs autocompletes the file name, it puts the part of the date. In these situations I have to write the rest of the date manually. Here is a solution, so that I can press Super+d and the suffix of today's date is written in the buffer. For example, if point is after "2019", when I press Super+d it becomes "2019-03-09".
(defun make-suffix (word1 word2) (cl-labels ((is-prefix (prefix list) (cond ((null prefix) t) ((null list) nil) ((equal (car prefix) (car list)) (is-prefix (cdr prefix) (cdr list))) (t nil))) (delete-x-elements (x list) (cond ((= x 0) list) ((null list) list) (t (delete-x-elements (- x 1) (cdr list))))) (make-suffix-rec (l1 l2) (cond ((null l1) l2) ((is-prefix l1 l2) (delete-x-elements (length l1) l2)) (t (make-suffix-rec (cdr l1) l2))))) (concat (make-suffix-rec (string-to-list word1) (string-to-list word2))))) (global-set-key (kbd "s-d") (lambda () (interactive) (let ((cw (current-word)) (ds (format-time-string "%Y-%m-%d"))) (insert (make-suffix cw ds)))))
So what do you think? Is it a good solution? Is it the right way to use elisp and Emacs?