123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- (defun makefile-beginning-of-command ()
- "Move to the beginning of the current command."
- (interactive)
- (if (save-excursion
- (forward-line -1)
- (makefile-line-continued-p))
- (forward-line -1))
- (beginning-of-line)
- (if (not (makefile-line-continued-p))
- nil
- (while (and (makefile-line-continued-p)
- (not (bobp)))
- (forward-line -1))
- (forward-line 1)))
- (defun makefile-end-of-command ()
- "Move to the end of the current command."
- (interactive)
- (end-of-line)
- (while (and (makefile-line-continued-p)
- (not (eobp)))
- (forward-line 1)
- (end-of-line)))
- (defun makefile-line-continued-p ()
- "Return non-nil if the current line ends in continuation."
- (save-excursion
- (end-of-line)
- (= (preceding-char) ?\\)))
- (defun makefile-move-to-macro (macro &optional next)
- "Move to the definition of MACRO. Return t if found.
- If NEXT is non-nil, move to the next occurrence of MACRO."
- (let ((oldpt (point)))
- (when (not next) (goto-char (point-min)))
- (if (re-search-forward (concat "^\\s-*" macro "\\s-*[+:?]?=") nil t)
- t
- (goto-char oldpt)
- nil)))
- (defun makefile-navigate-macro (stop-before)
- "In a list of files, move forward until STOP-BEFORE is reached.
- STOP-BEFORE is a regular expression matching a file name."
- (save-excursion
- (makefile-beginning-of-command)
- (let ((e (save-excursion
- (makefile-end-of-command)
- (point))))
- (if (re-search-forward stop-before nil t)
- (goto-char (match-beginning 0))
- (goto-char e)))))
- (defun makefile-macro-file-list (macro)
- "Return a list of all files in MACRO."
- (save-excursion
- (goto-char (point-min))
- (let ((lst nil))
- (while (makefile-move-to-macro macro t)
- (let ((e (save-excursion
- (makefile-end-of-command)
- (point))))
- (while (re-search-forward "\\s-**\\([-a-zA-Z0-9./_@$%(){}]+\\)\\s-*" e t)
- (let ((var nil)(varexp nil)
- (match (buffer-substring-no-properties
- (match-beginning 1)
- (match-end 1))))
- (if (not (setq var (makefile-extract-varname-from-text match)))
- (setq lst (cons match lst))
- (setq varexp (makefile-macro-file-list var))
- (dolist (V varexp)
- (setq lst (cons V lst))))))))
- (nreverse lst))))
- (defun makefile-extract-varname-from-text (text)
- "Extract the variable name from TEXT if it is a variable reference.
- Return nil if it isn't a variable."
- (save-match-data
- (when (string-match "\\$\\s(\\([A-Za-z0-9_]+\\)\\s)" text)
- (match-string 1 text))))
- (provide 'ede/makefile-edit)
|