Personal emacs config
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
4.5 KiB

  1. ;;; ad-javap-mode.el --- Javap major mode
  2. ;;; Version: 9
  3. ;;; URL: http://github.com/hiredman/javap-mode
  4. ;; Copyright (C) 2011 Kevin Downey
  5. ;; Permission is hereby granted, free of charge, to any person obtaining a copy
  6. ;; of this software and associated documentation files (the "Software"), to deal
  7. ;; in the Software without restriction, including without limitation the rights
  8. ;; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. ;; copies of the Software, and to permit persons to whom the Software is
  10. ;; furnished to do so, subject to the following conditions:
  11. ;; The above copyright notice and this permission notice shall be included in
  12. ;; all copies or substantial portions of the Software.
  13. ;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. ;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. ;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. ;; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. ;; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. ;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. ;; THE SOFTWARE.
  20. ;;; Commentary:
  21. ;; This code is taken from
  22. ;; https://github.com/hiredman/javap-mode/blob/master/javap-mode.el. This
  23. ;; package provides a mode for code disassembled by `javap', but also
  24. ;; installs a hook for disassembling the files. However, this is not
  25. ;; sufficient (for instance, it does not disassemble class files
  26. ;; inside jars).
  27. ;;
  28. ;; So this file is essentially the same as the original, but the
  29. ;; unconditional installation of `javap-mode''s hook is removed, since
  30. ;; `autodisass-java-bytecode' offers the same functionality (and some more).
  31. ;;; Code:
  32. (defconst ad-javap-font-lock-keywords
  33. (eval-when-compile
  34. `(
  35. ("line [0-9]+: [0-9]+" . font-lock-comment-face)
  36. ("\\<[a-zA-Z]+\\.[a-zA-Z0-9._]*[A-Z]+[a-zA-Z0-9/.$]*\\>" . font-lock-type-face) ;; borrowed from clojure-mode
  37. ("\\<[a-zA-Z]+/[a-zA-Z0-9/_]*[A-Z]+[a-zA-Z0-9/$]*\\>" . font-lock-type-face)
  38. ("[0-9]+:" . font-lock-comment-face)
  39. ("\\(#.+\\)" . font-lock-comment-face)
  40. ("\\(\\w\\|_\\)+(" . font-lock-preprocessor-face)
  41. (")" . font-lock-preprocessor-face)
  42. ("\\(invoke\\w+\\)" . font-lock-function-name-face)
  43. (,(regexp-opt '("boolean" "int" "void" "char"))
  44. . font-lock-type-face)
  45. (,(regexp-opt '("Exception table"
  46. "LocalVariableTable"
  47. "LineNumberTable")) . font-lock-warning-face)
  48. (".load_\\w+" . font-lock-keyword-face)
  49. (".load" . font-lock-keyword-face)
  50. (".store_\\w+" . font-lock-keyword-face)
  51. (".const_[0-9]+" . font-lock-keyword-face)
  52. (".return" . font-lock-keyword-face)
  53. (,(regexp-opt
  54. '("ifne" "athrow" "new" "dup" "aastore" "anewarray" "ifnull" "ifeq" "ifnonnull"
  55. "getstatic" "putfield" "getfield" "checkcast" "astore" "aload" "ldc" "goto" "putstatic"
  56. "pop" "instanceof" "ldc_w" "sipush" "bipush" "aaload" "bastore" "baload" "arraylength"
  57. "castore" "saload" "lastore" "daload" "dastore" "ifle" "istore" "lookupswitch" "iinc"
  58. "if_icmpge" "isub" "if_icmpgt" "if_acmpne" "iflt" "if_icmplt" "if_icmple" "dcmpg"
  59. "dcmpl" "ldc2_w" "lcmp" "fcmpg" "fcmpl" "ifge" "jsr" "ifgt" "ret" "aconst_null" "swap"
  60. "if_acmpeq" "dup_x2"))
  61. . font-lock-keyword-face)
  62. (".add" . font-lock-keyword-face)
  63. (,(regexp-opt
  64. '("public" "static" "final" "volatile" ";" "transient" "class" "extends" "implements"
  65. "synchronized" "protected" "private" "abstract" "interface" "Code:" "throws"))
  66. . font-lock-comment-face)
  67. ;; ("\\(\\w+\\)" . font-lock-keyword-face)
  68. ))
  69. "Default expressions to highlight in ad-javap mode.")
  70. (defvar ad-javap-mode-syntax-table (make-syntax-table)
  71. "Syntax table for use in ad-javap-mode.")
  72. ;;;###autoload
  73. (define-derived-mode ad-javap-mode fundamental-mode "ad-javap"
  74. "A major mode for viewing javap files."
  75. :syntax-table ad-javap-mode-syntax-table
  76. (modify-syntax-entry ?_ "w" ad-javap-mode-syntax-table)
  77. (modify-syntax-entry ?# "<" ad-javap-mode-syntax-table)
  78. (modify-syntax-entry ?\n ">" ad-javap-mode-syntax-table)
  79. (set (make-local-variable 'comment-start) "#")
  80. (set (make-local-variable 'comment-start-skip) "#")
  81. (set (make-local-variable 'font-lock-defaults) '(ad-javap-font-lock-keywords)))
  82. (provide 'ad-javap-mode)
  83. ;;; ad-javap-mode.el ends here