写了两个 elisp 函数
第一个:
(defun c-header (project module) "Insert some macro to prevent the header file included multiply" (interactive "sWhat's the project name? \nsWhat's the module name? ") (let ((p (upcase project)) (m (upcase module))) (insert (format "#ifndef %s_%s_HEADER\n" p m)) (insert (format "#define %s_%s_HEADER\n\n\n\n" p m)) (insert (format "#endif /* %s_%s_HEADER */\n" p m)) ) (let ((l (- (line-number-at-pos) 3))) (goto-line l)))
用于自动生成类似这样的 C 语言头文件代码:
#ifndef PM_POINTS_HEADER #define PM_POINTS_HEADER #endif /* PM_POINTS_HEADER */
第二个:
(defun gobject-macro (project object) "Insert some macroes about gobject" (interactive "sWhat's the project name? \nsWhat's the object name? ") (let ((P (upcase project)) (O (upcase object)) (p (downcase project)) (o (downcase object)) (pp (capitalize project)) (oo (capitalize object))) (insert (format "#define %s_TYPE_%s (%s_%s_get_type ())\n" P O p o)) (insert (format "#define %s_%s(object) (G_TYPE_CHECK_INSTANCE_CAST((object), %s_TYPE_%s, %s%s))\n" P O P O pp oo)) (insert (format "#define %s_%s_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), %s_TYPE_%s, %sClass))\n" P O P O pp oo)) (insert (format "#define %s_IS_%s(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), %s_TYPE_%s))\n" P O P O)) (insert (format "#define %s_IS_%s_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), %s_TYPE_%s))\n" P O P O)) (insert (format "#define %s_%s_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object), %s_TYPE_%s, %s%sClass))\n" P O P O pp oo))))
用于生成类似这样的 GObject 类型宏:
#define PM_TYPE_POINTS (pm_points_get_type ()) #define PM_POINTS(object) (G_TYPE_CHECK_INSTANCE_CAST((object), PM_TYPE_POINTS, PmPoints)) #define PM_POINTS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), PM_TYPE_POINTS, PmClass)) #define PM_IS_POINTS(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), PM_TYPE_POINTS)) #define PM_IS_POINTS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), PM_TYPE_POINTS)) #define PM_POINTS_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object), PM_TYPE_POINTS, PmPointsClass))