Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 36 additions & 26 deletions smart-compile.el
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
;;; smart-compile.el --- an interface to `compile'
;;; smart-compile.el --- an interface to `compile' -*- lexical-binding: t -*-

;; Copyright (C) 1998-2023 by Seiji Zenitani

Expand All @@ -10,6 +10,8 @@
;; URL(en): https://github.com/zenitani/elisp/blob/master/smart-compile.el
;; URL(jp): https://sci.nao.ac.jp/MEMBER/zenitani/elisp-j.html#smart-compile

;; Contributors: Sakito Hisakura, Greg Pfell, Pierre Téchoueyres

;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
Expand Down Expand Up @@ -97,6 +99,8 @@ The following %-sequences will be replaced by:

%o value of `smart-compile-option-string' ( \"user-defined\" ).

%p set cursor position in minibuffer or at end if not specified.

If the second item of the alist element is an emacs-lisp FUNCTION,
evaluate FUNCTION instead of running a compilation command.
"
Expand All @@ -119,19 +123,21 @@ This is usually the `default-directory', but if there's a \"build system\" (see
taken relative to.")
(make-variable-buffer-local 'smart-compile-build-root-directory)

(defconst smart-compile-replace-alist '(
("%F" . (buffer-file-name))
("%f" . (file-relative-name
(buffer-file-name)
smart-compile-build-root-directory))
("%n" . (file-relative-name
(file-name-sans-extension (buffer-file-name))
smart-compile-build-root-directory))
("%e" . (or (file-name-extension (buffer-file-name)) ""))
("%o" . smart-compile-option-string)
;; ("%U" . (user-login-name))
)
(defconst smart-compile-replace-alist
'(("%F" . (buffer-file-name))
("%f" . (file-relative-name
(buffer-file-name)
smart-compile-build-root-directory))
("%n" . (file-relative-name
(file-name-sans-extension (buffer-file-name))
smart-compile-build-root-directory))
("%e" . (or (file-name-extension (buffer-file-name)) ""))
("%o" . smart-compile-option-string)
("%p" . "")
;; ("%U" . (user-login-name))
)
"Alist of %-sequences for format control strings in `smart-compile-alist'.")

(put 'smart-compile-replace-alist 'risky-local-variable t)

(defcustom smart-compile-make-program "make "
Expand Down Expand Up @@ -321,19 +327,23 @@ which is defined in `smart-compile-alist'."
"Replace all the special format specifiers from `smart-compile-replace-alist' in FORMAT-STRING.

If `buffer-file-name' is not bound to a string, no replacements will be made."
(if (and (boundp 'buffer-file-name)
(stringp buffer-file-name))
(let ((rlist smart-compile-replace-alist)
(case-fold-search nil))
(while rlist
(while (string-match (caar rlist) format-string)
(setq format-string
(replace-match
(eval (cdar rlist)) t nil format-string)))
(setq rlist (cdr rlist))
)
))
format-string)
(let (curpos)
(if (and (boundp 'buffer-file-name)
(stringp buffer-file-name))
(let ((rlist smart-compile-replace-alist)
(case-fold-search nil)
token)
(while rlist
(let ((token (caar rlist))
(replace (cdar rlist)))
(while (string-match token format-string)
(when (string= "%p" token)
(setq curpos (match-beginning 0)))
(setq format-string
(replace-match
(eval (or replace "")) t nil format-string))))
(setq rlist (cdr rlist)))))
`(cons ,format-string ,(1+ (or curpos (length format-string))))))

(provide 'smart-compile)

Expand Down