A C standard library for sh3eb-elf.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

574 строки
21 KiB

  1. ;;; ============ NOTE WELL! =============
  2. ;;;
  3. ;;; You only need to use this file if you're using a version of Emacs
  4. ;;; prior to 20.1 to work on GDB. The only difference between this
  5. ;;; and the standard add-log.el provided with 19.34 is that it
  6. ;;; generates dates using the terser format used by Emacs 20. This is
  7. ;;; the format recommended for use in GDB ChangeLogs.
  8. ;;;
  9. ;;; To use this code, you should create a directory `~/elisp', save the code
  10. ;;; below in `~/elisp/add-log.el', and then put something like this in
  11. ;;; your `~/.emacs' file, to tell Emacs where to find it:
  12. ;;;
  13. ;;; (setq load-path
  14. ;;; (cons (expand-file-name "~/elisp")
  15. ;;; load-path))
  16. ;;;
  17. ;;; If you want, you can also byte-compile it --- it'll run a little
  18. ;;; faster, and use a little less memory. (Not that those matter much for
  19. ;;; this file.) To do that, after you've saved the text as
  20. ;;; ~/elisp/add-log.el, bring it up in Emacs, and type
  21. ;;;
  22. ;;; C-u M-x byte-compile-file
  23. ;;;
  24. ;;; --- Jim Blandy
  25. ;;; add-log.el --- change log maintenance commands for Emacs
  26. ;; Copyright (C) 1985, 1986, 1988, 1993, 1994 Free Software Foundation, Inc.
  27. ;; Keywords: maint
  28. ;; This file is part of GNU Emacs.
  29. ;; GNU Emacs is free software; you can redistribute it and/or modify
  30. ;; it under the terms of the GNU General Public License as published by
  31. ;; the Free Software Foundation; either version 2, or (at your option)
  32. ;; any later version.
  33. ;; GNU Emacs is distributed in the hope that it will be useful,
  34. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  35. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  36. ;; GNU General Public License for more details.
  37. ;; You should have received a copy of the GNU General Public License
  38. ;; along with GNU Emacs; see the file COPYING. If not, write to the
  39. ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  40. ;; Boston, MA 02111-1307, USA.
  41. ;;; Commentary:
  42. ;; This facility is documented in the Emacs Manual.
  43. ;;; Code:
  44. (defvar change-log-default-name nil
  45. "*Name of a change log file for \\[add-change-log-entry].")
  46. (defvar add-log-current-defun-function nil
  47. "\
  48. *If non-nil, function to guess name of current function from surrounding text.
  49. \\[add-change-log-entry] calls this function (if nil, `add-log-current-defun'
  50. instead) with no arguments. It returns a string or nil if it cannot guess.")
  51. ;;;###autoload
  52. (defvar add-log-full-name nil
  53. "*Full name of user, for inclusion in ChangeLog daily headers.
  54. This defaults to the value returned by the `user-full-name' function.")
  55. ;;;###autoload
  56. (defvar add-log-mailing-address nil
  57. "*Electronic mail address of user, for inclusion in ChangeLog daily headers.
  58. This defaults to the value of `user-mail-address'.")
  59. (defvar change-log-font-lock-keywords
  60. '(("^[SMTWF].+" . font-lock-function-name-face) ; Date line.
  61. ("^\t\\* \\([^ :\n]+\\)" 1 font-lock-comment-face) ; File name.
  62. ("(\\([^)\n]+\\)):" 1 font-lock-keyword-face)) ; Function name.
  63. "Additional expressions to highlight in Change Log mode.")
  64. (defvar change-log-mode-map nil
  65. "Keymap for Change Log major mode.")
  66. (if change-log-mode-map
  67. nil
  68. (setq change-log-mode-map (make-sparse-keymap))
  69. (define-key change-log-mode-map "\M-q" 'change-log-fill-paragraph))
  70. (defun change-log-name ()
  71. (or change-log-default-name
  72. (if (eq system-type 'vax-vms)
  73. "$CHANGE_LOG$.TXT"
  74. (if (or (eq system-type 'ms-dos) (eq system-type 'windows-nt))
  75. "changelo"
  76. "ChangeLog"))))
  77. ;;;###autoload
  78. (defun prompt-for-change-log-name ()
  79. "Prompt for a change log name."
  80. (let* ((default (change-log-name))
  81. (name (expand-file-name
  82. (read-file-name (format "Log file (default %s): " default)
  83. nil default))))
  84. ;; Handle something that is syntactically a directory name.
  85. ;; Look for ChangeLog or whatever in that directory.
  86. (if (string= (file-name-nondirectory name) "")
  87. (expand-file-name (file-name-nondirectory default)
  88. name)
  89. ;; Handle specifying a file that is a directory.
  90. (if (file-directory-p name)
  91. (expand-file-name (file-name-nondirectory default)
  92. (file-name-as-directory name))
  93. name))))
  94. ;;;###autoload
  95. (defun find-change-log (&optional file-name)
  96. "Find a change log file for \\[add-change-log-entry] and return the name.
  97. Optional arg FILE-NAME specifies the file to use.
  98. If FILE-NAME is nil, use the value of `change-log-default-name'.
  99. If 'change-log-default-name' is nil, behave as though it were 'ChangeLog'
  100. \(or whatever we use on this operating system).
  101. If 'change-log-default-name' contains a leading directory component, then
  102. simply find it in the current directory. Otherwise, search in the current
  103. directory and its successive parents for a file so named.
  104. Once a file is found, `change-log-default-name' is set locally in the
  105. current buffer to the complete file name."
  106. ;; If user specified a file name or if this buffer knows which one to use,
  107. ;; just use that.
  108. (or file-name
  109. (setq file-name (and change-log-default-name
  110. (file-name-directory change-log-default-name)
  111. change-log-default-name))
  112. (progn
  113. ;; Chase links in the source file
  114. ;; and use the change log in the dir where it points.
  115. (setq file-name (or (and buffer-file-name
  116. (file-name-directory
  117. (file-chase-links buffer-file-name)))
  118. default-directory))
  119. (if (file-directory-p file-name)
  120. (setq file-name (expand-file-name (change-log-name) file-name)))
  121. ;; Chase links before visiting the file.
  122. ;; This makes it easier to use a single change log file
  123. ;; for several related directories.
  124. (setq file-name (file-chase-links file-name))
  125. (setq file-name (expand-file-name file-name))
  126. ;; Move up in the dir hierarchy till we find a change log file.
  127. (let ((file1 file-name)
  128. parent-dir)
  129. (while (and (not (or (get-file-buffer file1) (file-exists-p file1)))
  130. (progn (setq parent-dir
  131. (file-name-directory
  132. (directory-file-name
  133. (file-name-directory file1))))
  134. ;; Give up if we are already at the root dir.
  135. (not (string= (file-name-directory file1)
  136. parent-dir))))
  137. ;; Move up to the parent dir and try again.
  138. (setq file1 (expand-file-name
  139. (file-name-nondirectory (change-log-name))
  140. parent-dir)))
  141. ;; If we found a change log in a parent, use that.
  142. (if (or (get-file-buffer file1) (file-exists-p file1))
  143. (setq file-name file1)))))
  144. ;; Make a local variable in this buffer so we needn't search again.
  145. (set (make-local-variable 'change-log-default-name) file-name)
  146. file-name)
  147. ;;;###autoload
  148. (defun add-change-log-entry (&optional whoami file-name other-window new-entry)
  149. "Find change log file and add an entry for today.
  150. Optional arg (interactive prefix) non-nil means prompt for user name and site.
  151. Second arg is file name of change log. If nil, uses `change-log-default-name'.
  152. Third arg OTHER-WINDOW non-nil means visit in other window.
  153. Fourth arg NEW-ENTRY non-nil means always create a new entry at the front;
  154. never append to an existing entry."
  155. (interactive (list current-prefix-arg
  156. (prompt-for-change-log-name)))
  157. (or add-log-full-name
  158. (setq add-log-full-name (user-full-name)))
  159. (or add-log-mailing-address
  160. (setq add-log-mailing-address user-mail-address))
  161. (if whoami
  162. (progn
  163. (setq add-log-full-name (read-input "Full name: " add-log-full-name))
  164. ;; Note that some sites have room and phone number fields in
  165. ;; full name which look silly when inserted. Rather than do
  166. ;; anything about that here, let user give prefix argument so that
  167. ;; s/he can edit the full name field in prompter if s/he wants.
  168. (setq add-log-mailing-address
  169. (read-input "Mailing address: " add-log-mailing-address))))
  170. (let ((defun (funcall (or add-log-current-defun-function
  171. 'add-log-current-defun)))
  172. paragraph-end entry)
  173. (setq file-name (expand-file-name (find-change-log file-name)))
  174. ;; Set ENTRY to the file name to use in the new entry.
  175. (and buffer-file-name
  176. ;; Never want to add a change log entry for the ChangeLog file itself.
  177. (not (string= buffer-file-name file-name))
  178. (setq entry (if (string-match
  179. (concat "^" (regexp-quote (file-name-directory
  180. file-name)))
  181. buffer-file-name)
  182. (substring buffer-file-name (match-end 0))
  183. (file-name-nondirectory buffer-file-name))))
  184. (if (and other-window (not (equal file-name buffer-file-name)))
  185. (find-file-other-window file-name)
  186. (find-file file-name))
  187. (or (eq major-mode 'change-log-mode)
  188. (change-log-mode))
  189. (undo-boundary)
  190. (goto-char (point-min))
  191. (let ((heading (format "%s %s <%s>"
  192. (format-time-string "%Y-%m-%d")
  193. add-log-full-name
  194. add-log-mailing-address)))
  195. (if (looking-at (regexp-quote heading))
  196. (forward-line 1)
  197. (insert heading "\n\n")))
  198. ;; Search only within the first paragraph.
  199. (if (looking-at "\n*[^\n* \t]")
  200. (skip-chars-forward "\n")
  201. (forward-paragraph 1))
  202. (setq paragraph-end (point))
  203. (goto-char (point-min))
  204. ;; Now insert the new line for this entry.
  205. (cond ((re-search-forward "^\\s *\\*\\s *$" paragraph-end t)
  206. ;; Put this file name into the existing empty entry.
  207. (if entry
  208. (insert entry)))
  209. ((and (not new-entry)
  210. (let (case-fold-search)
  211. (re-search-forward
  212. (concat (regexp-quote (concat "* " entry))
  213. ;; Don't accept `foo.bar' when
  214. ;; looking for `foo':
  215. "\\(\\s \\|[(),:]\\)")
  216. paragraph-end t)))
  217. ;; Add to the existing entry for the same file.
  218. (re-search-forward "^\\s *$\\|^\\s \\*")
  219. (goto-char (match-beginning 0))
  220. ;; Delete excess empty lines; make just 2.
  221. (while (and (not (eobp)) (looking-at "^\\s *$"))
  222. (delete-region (point) (save-excursion (forward-line 1) (point))))
  223. (insert "\n\n")
  224. (forward-line -2)
  225. (indent-relative-maybe))
  226. (t
  227. ;; Make a new entry.
  228. (forward-line 1)
  229. (while (looking-at "\\sW")
  230. (forward-line 1))
  231. (while (and (not (eobp)) (looking-at "^\\s *$"))
  232. (delete-region (point) (save-excursion (forward-line 1) (point))))
  233. (insert "\n\n\n")
  234. (forward-line -2)
  235. (indent-to left-margin)
  236. (insert "* " (or entry ""))))
  237. ;; Now insert the function name, if we have one.
  238. ;; Point is at the entry for this file,
  239. ;; either at the end of the line or at the first blank line.
  240. (if defun
  241. (progn
  242. ;; Make it easy to get rid of the function name.
  243. (undo-boundary)
  244. (insert (if (save-excursion
  245. (beginning-of-line 1)
  246. (looking-at "\\s *$"))
  247. ""
  248. " ")
  249. "(" defun "): "))
  250. ;; No function name, so put in a colon unless we have just a star.
  251. (if (not (save-excursion
  252. (beginning-of-line 1)
  253. (looking-at "\\s *\\(\\*\\s *\\)?$")))
  254. (insert ": ")))))
  255. ;;;###autoload
  256. (defun add-change-log-entry-other-window (&optional whoami file-name)
  257. "Find change log file in other window and add an entry for today.
  258. Optional arg (interactive prefix) non-nil means prompt for user name and site.
  259. Second arg is file name of change log. \
  260. If nil, uses `change-log-default-name'."
  261. (interactive (if current-prefix-arg
  262. (list current-prefix-arg
  263. (prompt-for-change-log-name))))
  264. (add-change-log-entry whoami file-name t))
  265. ;;;###autoload (define-key ctl-x-4-map "a" 'add-change-log-entry-other-window)
  266. ;;;###autoload
  267. (defun change-log-mode ()
  268. "Major mode for editing change logs; like Indented Text Mode.
  269. Prevents numeric backups and sets `left-margin' to 8 and `fill-column' to 74.
  270. New log entries are usually made with \\[add-change-log-entry] or \\[add-change-log-entry-other-window].
  271. Each entry behaves as a paragraph, and the entries for one day as a page.
  272. Runs `change-log-mode-hook'."
  273. (interactive)
  274. (kill-all-local-variables)
  275. (indented-text-mode)
  276. (setq major-mode 'change-log-mode
  277. mode-name "Change Log"
  278. left-margin 8
  279. fill-column 74
  280. indent-tabs-mode t
  281. tab-width 8)
  282. (use-local-map change-log-mode-map)
  283. ;; Let each entry behave as one paragraph:
  284. ;; We really do want "^" in paragraph-start below: it is only the lines that
  285. ;; begin at column 0 (despite the left-margin of 8) that we are looking for.
  286. (set (make-local-variable 'paragraph-start) "\\s *$\\|\f\\|^\\sw")
  287. (set (make-local-variable 'paragraph-separate) "\\s *$\\|\f\\|^\\sw")
  288. ;; Let all entries for one day behave as one page.
  289. ;; Match null string on the date-line so that the date-line
  290. ;; is grouped with what follows.
  291. (set (make-local-variable 'page-delimiter) "^\\<\\|^\f")
  292. (set (make-local-variable 'version-control) 'never)
  293. (set (make-local-variable 'adaptive-fill-regexp) "\\s *")
  294. (set (make-local-variable 'font-lock-defaults)
  295. '(change-log-font-lock-keywords t))
  296. (run-hooks 'change-log-mode-hook))
  297. ;; It might be nice to have a general feature to replace this. The idea I
  298. ;; have is a variable giving a regexp matching text which should not be
  299. ;; moved from bol by filling. change-log-mode would set this to "^\\s *\\s(".
  300. ;; But I don't feel up to implementing that today.
  301. (defun change-log-fill-paragraph (&optional justify)
  302. "Fill the paragraph, but preserve open parentheses at beginning of lines.
  303. Prefix arg means justify as well."
  304. (interactive "P")
  305. (let ((end (save-excursion (forward-paragraph) (point)))
  306. (beg (save-excursion (backward-paragraph)(point)))
  307. (paragraph-start (concat paragraph-start "\\|\\s *\\s(")))
  308. (fill-region beg end justify)))
  309. (defvar add-log-current-defun-header-regexp
  310. "^\\([A-Z][A-Z_ ]*[A-Z_]\\|[-_a-zA-Z]+\\)[ \t]*[:=]"
  311. "*Heuristic regexp used by `add-log-current-defun' for unknown major modes.")
  312. ;;;###autoload
  313. (defun add-log-current-defun ()
  314. "Return name of function definition point is in, or nil.
  315. Understands C, Lisp, LaTeX (\"functions\" are chapters, sections, ...),
  316. Texinfo (@node titles), Perl, and Fortran.
  317. Other modes are handled by a heuristic that looks in the 10K before
  318. point for uppercase headings starting in the first column or
  319. identifiers followed by `:' or `=', see variable
  320. `add-log-current-defun-header-regexp'.
  321. Has a preference of looking backwards."
  322. (condition-case nil
  323. (save-excursion
  324. (let ((location (point)))
  325. (cond ((memq major-mode '(emacs-lisp-mode lisp-mode scheme-mode
  326. lisp-interaction-mode))
  327. ;; If we are now precisely at the beginning of a defun,
  328. ;; make sure beginning-of-defun finds that one
  329. ;; rather than the previous one.
  330. (or (eobp) (forward-char 1))
  331. (beginning-of-defun)
  332. ;; Make sure we are really inside the defun found, not after it.
  333. (if (and (looking-at "\\s(")
  334. (progn (end-of-defun)
  335. (< location (point)))
  336. (progn (forward-sexp -1)
  337. (>= location (point))))
  338. (progn
  339. (if (looking-at "\\s(")
  340. (forward-char 1))
  341. (forward-sexp 1)
  342. (skip-chars-forward " '")
  343. (buffer-substring (point)
  344. (progn (forward-sexp 1) (point))))))
  345. ((and (memq major-mode '(c-mode c++-mode c++-c-mode objc-mode))
  346. (save-excursion (beginning-of-line)
  347. ;; Use eq instead of = here to avoid
  348. ;; error when at bob and char-after
  349. ;; returns nil.
  350. (while (eq (char-after (- (point) 2)) ?\\)
  351. (forward-line -1))
  352. (looking-at "[ \t]*#[ \t]*define[ \t]")))
  353. ;; Handle a C macro definition.
  354. (beginning-of-line)
  355. (while (eq (char-after (- (point) 2)) ?\\) ;not =; note above
  356. (forward-line -1))
  357. (search-forward "define")
  358. (skip-chars-forward " \t")
  359. (buffer-substring (point)
  360. (progn (forward-sexp 1) (point))))
  361. ((memq major-mode '(c-mode c++-mode c++-c-mode objc-mode))
  362. (beginning-of-line)
  363. ;; See if we are in the beginning part of a function,
  364. ;; before the open brace. If so, advance forward.
  365. (while (not (looking-at "{\\|\\(\\s *$\\)"))
  366. (forward-line 1))
  367. (or (eobp)
  368. (forward-char 1))
  369. (beginning-of-defun)
  370. (if (progn (end-of-defun)
  371. (< location (point)))
  372. (progn
  373. (backward-sexp 1)
  374. (let (beg tem)
  375. (forward-line -1)
  376. ;; Skip back over typedefs of arglist.
  377. (while (and (not (bobp))
  378. (looking-at "[ \t\n]"))
  379. (forward-line -1))
  380. ;; See if this is using the DEFUN macro used in Emacs,
  381. ;; or the DEFUN macro used by the C library.
  382. (if (condition-case nil
  383. (and (save-excursion
  384. (end-of-line)
  385. (while (= (preceding-char) ?\\)
  386. (end-of-line 2))
  387. (backward-sexp 1)
  388. (beginning-of-line)
  389. (setq tem (point))
  390. (looking-at "DEFUN\\b"))
  391. (>= location tem))
  392. (error nil))
  393. (progn
  394. (goto-char tem)
  395. (down-list 1)
  396. (if (= (char-after (point)) ?\")
  397. (progn
  398. (forward-sexp 1)
  399. (skip-chars-forward " ,")))
  400. (buffer-substring (point)
  401. (progn (forward-sexp 1) (point))))
  402. (if (looking-at "^[+-]")
  403. (get-method-definition)
  404. ;; Ordinary C function syntax.
  405. (setq beg (point))
  406. (if (and (condition-case nil
  407. ;; Protect against "Unbalanced parens" error.
  408. (progn
  409. (down-list 1) ; into arglist
  410. (backward-up-list 1)
  411. (skip-chars-backward " \t")
  412. t)
  413. (error nil))
  414. ;; Verify initial pos was after
  415. ;; real start of function.
  416. (save-excursion
  417. (goto-char beg)
  418. ;; For this purpose, include the line
  419. ;; that has the decl keywords. This
  420. ;; may also include some of the
  421. ;; comments before the function.
  422. (while (and (not (bobp))
  423. (save-excursion
  424. (forward-line -1)
  425. (looking-at "[^\n\f]")))
  426. (forward-line -1))
  427. (>= location (point)))
  428. ;; Consistency check: going down and up
  429. ;; shouldn't take us back before BEG.
  430. (> (point) beg))
  431. (let (end middle)
  432. ;; Don't include any final newline
  433. ;; in the name we use.
  434. (if (= (preceding-char) ?\n)
  435. (forward-char -1))
  436. (setq end (point))
  437. (backward-sexp 1)
  438. ;; Now find the right beginning of the name.
  439. ;; Include certain keywords if they
  440. ;; precede the name.
  441. (setq middle (point))
  442. (forward-word -1)
  443. ;; Ignore these subparts of a class decl
  444. ;; and move back to the class name itself.
  445. (while (looking-at "public \\|private ")
  446. (skip-chars-backward " \t:")
  447. (setq end (point))
  448. (backward-sexp 1)
  449. (setq middle (point))
  450. (forward-word -1))
  451. (and (bolp)
  452. (looking-at "struct \\|union \\|class ")
  453. (setq middle (point)))
  454. (buffer-substring middle end)))))))))
  455. ((memq major-mode
  456. '(TeX-mode plain-TeX-mode LaTeX-mode;; tex-mode.el
  457. plain-tex-mode latex-mode;; cmutex.el
  458. ))
  459. (if (re-search-backward
  460. "\\\\\\(sub\\)*\\(section\\|paragraph\\|chapter\\)" nil t)
  461. (progn
  462. (goto-char (match-beginning 0))
  463. (buffer-substring (1+ (point));; without initial backslash
  464. (progn
  465. (end-of-line)
  466. (point))))))
  467. ((eq major-mode 'texinfo-mode)
  468. (if (re-search-backward "^@node[ \t]+\\([^,\n]+\\)" nil t)
  469. (buffer-substring (match-beginning 1)
  470. (match-end 1))))
  471. ((eq major-mode 'perl-mode)
  472. (if (re-search-backward "^sub[ \t]+\\([^ \t\n]+\\)" nil t)
  473. (buffer-substring (match-beginning 1)
  474. (match-end 1))))
  475. ((eq major-mode 'fortran-mode)
  476. ;; must be inside function body for this to work
  477. (beginning-of-fortran-subprogram)
  478. (let ((case-fold-search t)) ; case-insensitive
  479. ;; search for fortran subprogram start
  480. (if (re-search-forward
  481. "^[ \t]*\\(program\\|subroutine\\|function\
  482. \\|[ \ta-z0-9*]*[ \t]+function\\)"
  483. nil t)
  484. (progn
  485. ;; move to EOL or before first left paren
  486. (if (re-search-forward "[(\n]" nil t)
  487. (progn (forward-char -1)
  488. (skip-chars-backward " \t"))
  489. (end-of-line))
  490. ;; Use the name preceding that.
  491. (buffer-substring (point)
  492. (progn (forward-sexp -1)
  493. (point)))))))
  494. (t
  495. ;; If all else fails, try heuristics
  496. (let (case-fold-search)
  497. (end-of-line)
  498. (if (re-search-backward add-log-current-defun-header-regexp
  499. (- (point) 10000)
  500. t)
  501. (buffer-substring (match-beginning 1)
  502. (match-end 1))))))))
  503. (error nil)))
  504. (defvar get-method-definition-md)
  505. ;; Subroutine used within get-method-definition.
  506. ;; Add the last match in the buffer to the end of `md',
  507. ;; followed by the string END; move to the end of that match.
  508. (defun get-method-definition-1 (end)
  509. (setq get-method-definition-md
  510. (concat get-method-definition-md
  511. (buffer-substring (match-beginning 1) (match-end 1))
  512. end))
  513. (goto-char (match-end 0)))
  514. ;; For objective C, return the method name if we are in a method.
  515. (defun get-method-definition ()
  516. (let ((get-method-definition-md "["))
  517. (save-excursion
  518. (if (re-search-backward "^@implementation\\s-*\\([A-Za-z_]*\\)" nil t)
  519. (get-method-definition-1 " ")))
  520. (save-excursion
  521. (cond
  522. ((re-search-forward "^\\([-+]\\)[ \t\n\f\r]*\\(([^)]*)\\)?\\s-*" nil t)
  523. (get-method-definition-1 "")
  524. (while (not (looking-at "[{;]"))
  525. (looking-at
  526. "\\([A-Za-z_]*:?\\)\\s-*\\(([^)]*)\\)?[A-Za-z_]*[ \t\n\f\r]*")
  527. (get-method-definition-1 ""))
  528. (concat get-method-definition-md "]"))))))
  529. (provide 'add-log)
  530. ;;; add-log.el ends here