From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Glenn Morris Newsgroups: gmane.emacs.help Subject: Re: Can F90-mode blink at an "else"? Date: Sun, 11 Dec 2005 03:37:11 +0000 Organization: None Message-ID: References: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1134272489 5644 80.91.229.2 (11 Dec 2005 03:41:29 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 11 Dec 2005 03:41:29 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Dec 11 04:41:28 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1ElI4I-0000Js-5L for geh-help-gnu-emacs@m.gmane.org; Sun, 11 Dec 2005 04:40:10 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1ElI4h-0000Yw-AT for geh-help-gnu-emacs@m.gmane.org; Sat, 10 Dec 2005 22:40:35 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!logbridge.uoregon.edu!feed3.jnfs.ja.net!jnfs.ja.net!gemini.csx.cam.ac.uk!news.cam.ac.uk!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 133 Original-NNTP-Posting-Host: xserv2.ast.cam.ac.uk X-Spook: IRA maverick sniper c4 arrangements strategic Terra X-Ran: z*l5T`zcorNg+%p.I>]8qb`tEoHLP"(L+t`_V[CGOq/Yu!g??EV1)8&M(NxXP"%[vd;NA^ X-Hue: magenta X-Attribution: GM Mail-Copies-To: nobody User-Agent: Gnus (www.gnus.org), GNU Emacs (www.gnu.org/software/emacs/) Cancel-Lock: sha1:iOsnIH9qF4UOa6P0u9hOJ2rLN8Y= Original-Xref: shelby.stanford.edu gnu.emacs.help:136251 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:31865 Archived-At: Glenn Morris wrote: > Svend Tollak Munkejord wrote: > >> In F90-mode, when I use (setq f90-smart-end 'blink), Emacs only >> indicates the matching if when the cursor is at the "end if", but not >> when it is at the "else". >> >> Does anybody know how I can make Emacs always show me the matching if? > > Sorry, I don't think there is any simple way to do this without > re-writing parts of the f90-indent-line and f90-match-end functions. > I'll try to add it as a feature for some future version. Here's a briefly tested patch against the current CVS. *** f90.el 04 Dec 2005 22:56:07 -0800 1.88 --- f90.el 10 Dec 2005 19:33:07 -0800 *************** *** 991,996 **** --- 991,1006 ---- "?\\([ \t]+\\(\\sw+\\)\\)?\\>")) (list (match-string 1) (match-string 3)))) + (defsubst f90-looking-at-else-like () + "Return KIND if an ELSE or CASE statement starts after point. + Returns \"selectcase\", \"elseif\", \"elsewhere\", \"else\", or nil." + (when (looking-at f90-else-like-re) + (cond ((looking-at "case[ \t]*\\(default\\|\(\\)") + "selectcase") + ((or (looking-at "else[ \t]*\\(if\\)\\>") + (looking-at "else\\(where\\)?\\>")) + (concat "else" (match-string 1)))))) + (defsubst f90-comment-indent () "Return the indentation to be used for a comment starting at point. Used for `comment-indent-function' by F90 mode. *************** *** 1430,1436 **** (skip-chars-forward " \t")) (if (looking-at "!") (setq indent (f90-comment-indent)) ! (and f90-smart-end (looking-at "end") (f90-match-end)) (setq indent (f90-calculate-indent))) (or (= indent (current-column)) --- 1440,1446 ---- (skip-chars-forward " \t")) (if (looking-at "!") (setq indent (f90-comment-indent)) ! (and f90-smart-end (looking-at (concat "end\\|" f90-else-like-re)) (f90-match-end)) (setq indent (f90-calculate-indent))) (or (= indent (current-column)) *************** *** 1719,1724 **** --- 1729,1757 ---- (replace-match "")))) (or (looking-at "[ \t]*!") (delete-horizontal-space)))) + (defun f90-else-like-match (beg-block else-block) + "Match else-struct with beg-struct and complete else-struct if possible. + BEG-BLOCK is the type of block as indicated at the start (e.g., if). + ELSE-BLOCK is the type of block as indicated at the else (may be nil)." + (if (not (member beg-block '("if" "where" "select"))) + (if beg-block + (message "`%s' block cannot have an ELSE/CASE." beg-block) + (message "No beginning for ELSE/CASE.")) + (let ((else-type (cond + ((string-equal else-block "selectcase") "select") + ((string-match "else\\(if\\|where\\)" else-block) + (match-string 1 else-block))))) + (unless (f90-equal-symbols beg-block else-type) + (if (or else-type + (f90-equal-symbols beg-block "select")) + (progn + (message "%s does not match %s." else-block beg-block) + (end-of-line)) + (cond ((string-equal beg-block "where") + (message "Inserting %s." beg-block) + (search-forward "else" (line-end-position)) + (insert beg-block)))))))) + (defun f90-match-end () "From an end block statement, find the corresponding block and name." (interactive) *************** *** 1726,1736 **** (top-of-window (window-start)) (end-point (point)) (case-fold-search t) ! matching-beg beg-name end-name beg-block end-block end-struct) (when (save-excursion (beginning-of-line) (skip-chars-forward " \t0-9") ! (setq end-struct (f90-looking-at-program-block-end))) ! (setq end-block (car end-struct) ! end-name (car (cdr end-struct))) (save-excursion (beginning-of-line) (while (and (> count 0) --- 1759,1769 ---- (top-of-window (window-start)) (end-point (point)) (case-fold-search t) ! matching-beg beg-name beg-block end-struct else-struct) (when (save-excursion (beginning-of-line) (skip-chars-forward " \t0-9") ! (or (setq end-struct ! (f90-looking-at-program-block-end)) ! (setq else-struct (f90-looking-at-else-like)))) (save-excursion (beginning-of-line) (while (and (> count 0) *************** *** 1773,1779 **** beg-name (car (cdr matching-beg))) (goto-char end-point) (beginning-of-line) ! (f90-block-match beg-block beg-name end-block end-name)))))) (defun f90-insert-end () "Insert a complete end statement matching beginning of present block." --- 1806,1815 ---- beg-name (car (cdr matching-beg))) (goto-char end-point) (beginning-of-line) ! (if else-struct ! (f90-else-like-match beg-block else-struct) ! (f90-block-match beg-block beg-name ! (car end-struct) (cadr end-struct)))))))) (defun f90-insert-end () "Insert a complete end statement matching beginning of present block."