;;; what-defun-am-i-in.el ;;; ;;; Copyright (C) 1997, 1998, 2004, 2007, 2008 Thien-Thi Nguyen ;;; ;;; This file is part of ttn's personal elisp library, released under ;;; the terms of the GNU General Public License as published by the ;;; Free Software Foundation; either version 3, or (at your option) any ;;; later version. There is NO WARRANTY. See file COPYING for details. ;;; Description: Determine where cursor is syntactically for several modes. ;;;###autoload (defun where-am-i () "Summarize in the echo area the forms surrounding point. See also variable `max-mini-window-height'." (interactive) (save-excursion (font-lock-fontify-region (save-excursion (beginning-of-defun) (point)) (line-end-position))) (flet ((line () (buffer-substring (line-beginning-position) (min (point-max) (1+ (line-end-position)))))) (let ((acc (list (line) (concat ;; Use text properties instead of ;; `make-string' to be upward compatible ;; w/ a hopefully not-too-distant future ;; float-returning `current-column'. (propertize " " 'display `(space :align-to ,(current-column))) "^")))) (save-excursion (while (ignore-errors (while (memq (get-text-property (point) 'face) '(font-lock-comment-face font-lock-comment-delimiter-face font-lock-string-face)) (forward-char -1)) (backward-up-list) (pushnew (line) acc :test 'string=)))) (message "%s" (apply 'concat acc))))) ;;;###autoload (defun mouse-where-am-i (event) "Set point at mouse EVENT (click) position and do `where-am-i' there." (interactive "@e") (mouse-set-point event) (where-am-i)) ;;;###autoload (defun what-defun-am-i-in () "Returns string of current mode-specific \"defun\". If run interactively, display using `message'." (interactive) (let (ret) (save-excursion (let ((defun-prompt-regexp (case major-mode ((verilog-mode) "module\\s-+\\S-+\\s-*") (t nil)))) (beginning-of-defun)) (case major-mode ((scheme-mode) (re-search-forward "define\\S-* +\\(.*\\)")) ((lisp-interaction-mode lisp-mode emacs-lisp-mode) (re-search-forward "defun +\\(\\S-+\\)")) ((c-mode c++-mode) (re-search-backward "\\(^\\S-+\\)")) ((verilog-mode) (re-search-forward "module +\\(\\S-+\\)")) )) (setq ret (buffer-substring (match-beginning 1) (match-end 1))) (if (interactive-p) (message ret) ret))) (provide 'what-defun-am-i-in) ;;; what-defun-am-i-in.el ends here