Skip to content

Commit

Permalink
Make preprocess narrow to region
Browse files Browse the repository at this point in the history
  • Loading branch information
smagnuso committed Oct 2, 2012
1 parent 4107818 commit 4cb300e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
27 changes: 25 additions & 2 deletions rtags.el
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,39 @@
(defun rtags-preprocess-file (&optional buffer)
(interactive)
(let ((fn (buffer-file-name buffer))
(bufname))
bufname narrow-start narrow-end)
(if (and mark-active
(not (equal (region-beginning) (region-end))))
(setq narrow-start (+ 1 (count-lines (point-min) (region-beginning)))
narrow-end (+ 1 (count-lines (point-min) (region-end)))))
(if fn
(progn
(setq bufname (format "*RTags preprocessed %s*" fn))
(if (get-buffer bufname)
(kill-buffer bufname))
(switch-to-buffer (generate-new-buffer bufname))
(rtags-call-rc nil "--preprocess" fn)
(if (and narrow-start narrow-end)
(let ((match-regexp (concat "^# \\([0-9]*\\) \"" (file-truename fn) "\""))
last-match last-line start end)
(while (re-search-forward match-regexp nil t)
(let ((current-line (string-to-int (match-string 1))))
(if (and (not start) (> current-line narrow-start)) (setq start (+ (count-lines (point-min) last-match) (- narrow-start last-line))))
(if (and (not end) (> current-line narrow-end)) (setq end (+ (count-lines (point-min) last-match) (- narrow-end last-line))))
(setq last-line current-line)
(setq last-match (point))))
(if last-match
(progn
(if (not start) (setq start (+ (count-lines (point-min) last-match) (- narrow-start last-line))))
(if (not end) (setq end (+ (count-lines (point-min) last-match) (- narrow-end last-line))))))
(if (and start end)
(progn
(goto-char (point-min))
(narrow-to-region (point-at-bol (+ start 1)) (point-at-bol (+ end 1)))))))
(setq buffer-read-only t)
(c++-mode)
(setq buffer-read-only nil)))))
(local-set-key "q" 'bury-buffer)
))))

(defun rtags-reparse-file(&optional buffer)
(interactive)
Expand Down
15 changes: 3 additions & 12 deletions src/Preprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,22 @@ void Preprocessor::preprocess()
{
if (!mProc) {
mProc = new Process;
mProc->readyReadStdOut().connect(this, &Preprocessor::onProcessReadyRead);
mProc->readyReadStdErr().connect(this, &Preprocessor::onProcessReadyRead);
mProc->finished().connect(this, &Preprocessor::onProcessFinished);
}
mArgs.args.append("-E");
mArgs.args.append(mArgs.sourceFile);
mProc->start(mArgs.compiler, mArgs.args);
}

void Preprocessor::onProcessReadyRead()
void Preprocessor::onProcessFinished()
{
if (!mWrittenArguments) {
mConnection->write<256>("// %s %s", mArgs.compiler.constData(),
ByteArray::join(mArgs.args, ' ').constData());
mWrittenArguments = true;
}
mConnection->write<256>("// %s %s", mArgs.compiler.constData(),
ByteArray::join(mArgs.args, ' ').constData());
mConnection->write(mProc->readAllStdOut());
const ByteArray err = mProc->readAllStdErr();
if (!err.isEmpty()) {
mConnection->write<1024>("/* %s */", err.constData());
}
}

void Preprocessor::onProcessFinished()
{
mConnection->finish();
deleteLater();
}

0 comments on commit 4cb300e

Please sign in to comment.