jar-hacks.el 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. ; Comment out region
  2. (defun comment-out-region (arg)
  3. "Insert comment string at beginning of each line in the region."
  4. (interactive "P")
  5. (let (start end)
  6. (if (< (point) (mark))
  7. (setq start (point) end (mark-marker))
  8. (setq start (mark) end (point-marker)))
  9. (save-excursion
  10. (untabify start (marker-position end))
  11. (goto-char start)
  12. (if (not (bolp))
  13. (progn (end-of-line) (forward-char)))
  14. (while (< (point) (marker-position end))
  15. (if (eq arg '-)
  16. (if (looking-at comment-start)
  17. (delete-char (length comment-start)))
  18. (insert comment-start))
  19. (end-of-line)
  20. (forward-char)))))
  21. ;(defun uncomment-out-region (arg)
  22. ; (interactive nil)
  23. ; (comment-out-region '-))
  24. ; Mini-Find Tag
  25. (defvar last-mini-tag "" "Last tag sought by mini-find-tag.")
  26. (defun mini-find-tag (tagname &optional next)
  27. "Search for a definition of TAGNAME in current buffer.
  28. If TAGNAME is a null string, the expression in the buffer
  29. around or before point is used as the tag name.
  30. If second arg NEXT is non-nil (interactively, with prefix arg),
  31. searches for the next definition in the buffer
  32. that matches the tag name used in the previous mini-find-tag."
  33. (interactive (if current-prefix-arg
  34. '(nil t)
  35. (list (read-string "Mini-find tag: "))))
  36. (if (equal tagname "") ;See definition of find-tag.
  37. (setq tagname (save-excursion
  38. (buffer-substring
  39. (progn (backward-sexp 1) (point))
  40. (progn (forward-sexp 1) (point))))))
  41. (let ((pt (save-excursion
  42. (if (not next)
  43. (goto-char (point-min))
  44. (setq tagname last-mini-tag))
  45. (setq last-mini-tag tagname)
  46. (if (re-search-forward
  47. (concat "^(def.*" tagname)
  48. nil t)
  49. (point)
  50. nil))))
  51. (if pt
  52. (progn (set-mark-command nil)
  53. (goto-char pt))
  54. (signal 'search-failed '()))))
  55. ; indent-differently
  56. (defun indent-differently ()
  57. "Make the current line indent like the body of a special form by
  58. changing the operator's scheme-indent-hook appropriately."
  59. (interactive nil)
  60. (let ((here (point)))
  61. (save-excursion
  62. (back-to-indentation)
  63. (backward-up-list 1)
  64. (forward-char 1)
  65. (let ((i -1)
  66. (function nil)
  67. (p (point)))
  68. (while (<= (point) here)
  69. (setq i (+ i 1))
  70. (forward-sexp 1)
  71. (if (= i 0)
  72. (setq function (buffer-substring p (point)))))
  73. (setq i (- i 1))
  74. (let ((name (intern (downcase function))))
  75. (cond ((equal (get name 'scheme-indent-hook) i)
  76. (message "Indent %s nil" name)
  77. (put name 'scheme-indent-hook nil))
  78. (t
  79. (message "Indent %s %d" name i)
  80. (put name 'scheme-indent-hook i))))))
  81. (scheme-indent-line)))